UniWindowController (UniWinC)

repository·main·Indexed 20 days ago

https://github.com/kirurobo/uniwindowcontroller

A library for Unity-based standalone applications on Windows and macOS that provides control over window properties. It supports transparency, borderless mode, position, size, and file/folder drop support. Key features include hit testing for click-through behavior (via Opacity or Raycast methods), programmatic window manipulation through UniWindowController.cs, and system file dialogs via FilePanel. Version 0.9.8.

Tokens
2.7K
Snippets
2
Records
18
Agent score
70%

What's inside UniWindowController

  1. Understand Hit Testing (Click-through behavior)

    main

    When a window is transparent, it still exists as a rectangular area. To allow users to click "through" the transparent parts to windows underneath, UniWindowController uses "Hit Testing".

    You can choose between two methods:

    MethodDescriptionNote
    OpacityChecks the alpha/transparency of the pixel.Most natural look, but higher CPU cost. (Default)
    RaycastChecks for the presence of a Collider.More performant, but requires you to set up Colliders on your UI/objects.

    If you use Raycast and forget to provide Colliders, the window will become unclickable.

  2. Understand Hit Testing and Click-Through behavior

    main

    When a window is transparent, it still exists as a rectangular area. To allow users to click "through" the transparent parts to windows underneath, UniWindowController uses hit testing.

    There are two methods for hit testing:

    NameMethodNote
    OpacityCheck transparencyMatches appearance naturally but is computationally heavy.
    RaycastCheck colliderLightweight and recommended for performance, but requires you to set up colliders on your objects.

    If you use the Raycast method and forget to add colliders, you will not be able to interact with the screen.

  3. Understand Hit Testing and Transparency methods

    main

    Since windows are technically rectangular, UniWindowController uses "Hit Testing" to allow mouse clicks to pass through transparent areas to windows underneath (click-through).

    Hit Test Methods

    NameMethodNote
    OpacityChecks transparencyNatural look, but higher CPU cost. (Default)
    RaycastChecks CollidersMore performant, but requires you to set up Colliders.

    Windows-only Transparency Methods

    On Windows, you can choose between two transparency modes. Note that ColorKey is better for touch input but lacks semi-transparency.

    NameDescriptionNote
    AlphaReflects rendering alphaStandard mode.
    ColorKeyTransparently renders a single RGB colorLower performance, but provides more natural touch interaction.
  4. Use UniWindowController in your Unity project

    main

    To set up window control in your scene, follow these steps:

    1. Add the Prefab: Drag the UniWindowController prefab from Runtime/Prefabs into your scene.
    2. Configure Settings: Select the UniWindowController instance in the Inspector.
      • Use the provided button to automatically update necessary Player Settings.
      • Adjust settings like IsTransparent to your preference.
    3. Enable Window Dragging (Optional): If you want to move the window by dragging with the mouse, add the DragMoveCanvas prefab from Runtime/Prefabs to your scene.
      • Requirement: An EventSystem must be present in the scene. If you don't have one, go to UI -> Event System to add it.
    4. Build and Run: Build the project as a PC / Mac Standalone application and run the build.
  5. Set up UniWindowController in your Unity project

    main

    Follow these steps to integrate the window controller into your scene:

    1. Add the Controller: Drag the UniWindowController prefab from Runtime/Prefabs into your scene.
    2. Configure Player Settings: Select the UniWindowController instance in the scene. In the Inspector, use the provided green button to automatically fix the necessary Player Settings.
    3. Adjust Transparency: Modify settings like IsTransparent in the Inspector to achieve your desired window look.
    4. Enable Window Dragging (Optional): If you want users to move the window by dragging the mouse, add the DragMoveCanvas prefab from Runtime/Prefabs to your scene.
      • Note: An EventSystem is required. If your scene lacks one, go to UI > Event System to add it.
    5. Build: Build your project for PC/Mac Standalone and launch the build. (Note: Transparency features are not available within the Unity Editor itself).
  6. Set up UniWindowController in your Unity scene

    main

    To use the controller in your project, follow these steps:

    1. Add the Prefab: Add the UniWindowController prefab from Runtime/Prefabs to your scene.
    2. Configure Inspector: Inspect the UniWindowController instance.
      • Use the green button in the inspector to automatically apply necessary Player Settings changes.
      • Configure settings like IsTransparent according to your needs.
    3. Enable Window Dragging (Optional): If you want to move the window by dragging a specific area, add the DragMoveCanvas prefab from Runtime/Prefabs.
      • Note: This requires an EventSystem. If your scene doesn't have one, add it via UI -> Event System.
    4. Build: Build the project as a PC / Mac Standalone application and run the build.
  7. Install UniWindowController via UPM or UnityPackage

    main

    You can install UniWindowController using two methods:

    Method A: Unity Package Manager (UPM)

    This is recommended for easier version updates.

    1. Open the Package Manager from the Window menu in the Unity Editor.
    2. Click the [+] button and select Add package from git URL....
    3. Enter the following URL: https://github.com/kirurobo/UniWindowController.git#upm and click Add.

    Method B: UnityPackage

    1. Download the .unitypackage file from the Releases page.
    2. Import the package into your Unity project.
    https://github.com/kirurobo/UniWindowController.git#upm
  8. Configure URP for background transparency

    main

    When using the Universal Render Pipeline (URP), you must ensure the alpha channel is maintained to support transparency. Apply these settings:

    1. Disable HDR: On your Main Camera (GameObject), go to the Camera component > Output and set HDR to Off.
    2. Enable Alpha Processing: Ensure AlphaProcessing is enabled in your URP settings.
  9. Troubleshooting: Transparency and Limitations

    main

    Transparency Issues

    • Direct3D12: Background transparency is not supported.
    • Direct3D11: To enable transparency, you must disable Use DXGI flip model swapchain for D3D11 in Unity settings.
    • Unity Editor: Transparency does not work inside the Unity Editor. You must build and run the application to see transparency effects.

    General Limitations

    • Touch Input: Support is limited. On Windows, switching TransparentType to ColorKey improves touch feel at the cost of semi-transparency.
    • Multiple Windows: The package does not support multiple windows.
    • Platform: Supports Windows 10/11 and macOS.
  10. Move the window using UniWindowMoveHandler.cs

    main

    To allow users to move the window by dragging a specific UI element (like a handle bar):

    1. Attach the UniWindowMoveHandler.cs script to a UI element (the element must be a Raycast Target).
    2. The DragMoveCanvas prefab includes a Panel that covers the entire screen. This panel is set to the Ignore Raycast layer so that it doesn't interfere with the automatic hit test, allowing you to drag from anywhere on the screen while still allowing other UI operations to take precedence.
  11. Manipulate window properties via UniWindowController.cs

    main

    The UniWindowController script is the primary interface for controlling the window via C# scripting. The following properties can be manipulated:

    NameTypeDescription
    isTransparentboolSet/unset for transparent (non-rectangular) windows
    isTopmostboolAlways set/unset to topmost
    isZoomedboolMaximize/unmaximize the window; also returns current state
    isHitTestEnabledboolEnables/disables automatic hit test. If enabled, isClickThrough updates based on mouse position
    isClickThroughboolSets/unset the click-through state
    windowPositionVector2Get/set window position. Origin is the lower left corner of the main monitor (positive upward)
    windowSizeVector2Get/set the window size