91 lines
3.8 KiB
Markdown
91 lines
3.8 KiB
Markdown
# XUniWindowController
|
|
|
|
**XUniWindowController** is a Unity native plugin that provides comprehensive standalone application window control for Windows and macOS builds.
|
|
|
|
It is a UPM package port of [UniWindowController](https://github.com/kirurobo/UniWindowController) by Kirurobo.
|
|
|
|
## Usage
|
|
|
|
Add the `UniWindowController` component to any GameObject in your scene. Access it via:
|
|
|
|
```csharp
|
|
var winc = UniWindowController.current;
|
|
winc.isTransparent = true;
|
|
winc.isTopmost = true;
|
|
winc.windowSize = new Vector2(1280, 720);
|
|
```
|
|
|
|
### Properties
|
|
|
|
| Property | Type | Description |
|
|
|----------|------|-------------|
|
|
| `isTransparent` | `bool` | Enable/disable window transparency |
|
|
| `alphaValue` | `float` | Window opacity (0.0 ~ 1.0) |
|
|
| `isTopmost` | `bool` | Keep window always on top |
|
|
| `isBottommost` | `bool` | Keep window always on bottom |
|
|
| `isZoomed` | `bool` | Maximize/restore window |
|
|
| `isClickThrough` | `bool` | Enable/disable mouse click-through |
|
|
| `windowPosition` | `Vector2Int` | Get/set window position (screen coordinates) |
|
|
| `windowSize` | `Vector2Int` | Get/set window size (pixels) |
|
|
| `clientSize` | `Vector2Int` | Get client area size (read-only) |
|
|
| `allowDropFiles` | `bool` | Enable/disable file drag-and-drop |
|
|
| `hitTestType` | `HitTestType` | Click-through detection mode |
|
|
| `transparentType` | `TransparentType` | Transparency algorithm |
|
|
| `shouldFitMonitor` | `bool` | Fit window to a specific monitor |
|
|
| `monitorToFit` | `int` | Target monitor index |
|
|
|
|
### Events
|
|
|
|
| Event | Description |
|
|
|-------|-------------|
|
|
| `OnStateChanged` | Fired when window style, z-order, or size changes |
|
|
| `OnMonitorChanged` | Fired when display configuration changes (resolution, monitor count) |
|
|
| `OnDropFiles` | Fired when files are dragged and dropped onto the window |
|
|
|
|
## Samples
|
|
|
|
Import samples via **Package Manager > XUniWindowController > Samples**.
|
|
|
|
The following samples are included:
|
|
|
|
- **Menu** — Navigation menu for browsing all sample scenes
|
|
- **SimpleSample** — Minimal setup demonstrating basic window control
|
|
- **UiSample** — Complete UI with toggles, sliders, dropdowns for all window properties
|
|
- **Fullscreen** — Fullscreen mode with right-click context menu and a 3D snowman scene
|
|
- **FileDialog** — Native file open/save dialog integration
|
|
|
|
## Technical Details
|
|
|
|
### Windows Architecture
|
|
|
|
The plugin uses `LibUniWinC.dll` (C++ Win32 DLL) to control window behavior through native Win32 API calls:
|
|
|
|
- `SetWindowLong` / `GetWindowLong` — Window style modification (borderless, layered, click-through)
|
|
- `SetWindowPos` — Position, size, and Z-order (topmost/bottommost)
|
|
- `DwmExtendFrameIntoClientArea` — DWM alpha transparency
|
|
- `SetLayeredWindowAttributes` — ColorKey transparency mode
|
|
- `SetWindowsHookEx` / custom `WNDPROC` — Window message interception (file drop, display change, resize)
|
|
- `DragAcceptFiles` — File drag-and-drop
|
|
- `GetOpenFileNameW` / `GetSaveFileNameW` — Native file dialogs
|
|
|
|
### macOS Architecture
|
|
|
|
The plugin uses `LibUniWinC.bundle` (Swift / Cocoa) to control window behavior through Cocoa APIs:
|
|
|
|
- `NSWindow.styleMask` — Borderless mode
|
|
- `NSWindow.level` — Z-order (topmost/bottommost)
|
|
- `NSWindow.isOpaque` / `backgroundColor` — Transparency
|
|
- `NSWindow.ignoresMouseEvents` — Click-through
|
|
- `NSDraggingDestination` protocol — File drag-and-drop
|
|
- `NSOpenPanel` / `NSSavePanel` — Native file dialogs
|
|
- `constrainFrameRect` method swizzling — Free window positioning
|
|
- `NotificationCenter` — Window state change observation
|
|
|
|
### Package Contents
|
|
|
|
| Location | Description |
|
|
|----------|-------------|
|
|
| `Runtime/Scripts/` | Core C# scripts (UniWindowController, UniWinCore, FilePanel, etc.) |
|
|
| `Runtime/Plugins/` | Native plugin binaries (.dll for Windows, .bundle for macOS) |
|
|
| `Editor/Scripts/` | Editor extensions (Inspector UI, batch build, PlayerSettings validation) |
|
|
| `Samples~/` | Sample scenes and scripts | |