Home

Awesome

UniWindowController

Unified window controller for macOS and Windows
Abbreviation:UniWinC

license

README

Overview

This is a library for apps built for Windows / macOS standalone with Unity.
This library controls transparency, borderless, position, size, etc. of its own window.
And it allows also accept file and folder drops.

uniwinc
https://twitter.com/i/status/1314440790945361920

Demo

You can find some sample builts on the Release page.

Installation

If you use the UPM, you can also perform version upgrades from UPM.

A. Using the Unity Package Manager (UPM)

  1. Open [Package Manager] from the [Window] menu of the Unity Editor.
  2. Select [+] and then select [Add package from git URL...].
    image
  3. Enter https://github.com/kirurobo/UniWindowController.git#upm and [Add].
    image

B. Using an UnityPackage

  1. Download an .unitypackage file from the Release page.
  2. Import the asset in the Unity Editor.

Use in your Unity project

  1. Add the UniWindowController prefab in the Runtime/Prefabs to your scene.
  2. Select the UniWindowController placed scene, and watch the inspector.
  1. Add DragMoveCanvas prefab in the Runtime/Prefabs if you want to move the window by mouse dragging.
  1. Build for PC / Mac standalone
  2. Launch the build

Limitations

See also Issues for known issues.

System requirements

Development environment is Unity 2020.4.30f1, Windows 11 / macOS 13.3

Additional information

About the hit test

When the window is successfully made transparent, it looks as if it is a non-rectangular window.
However, this is only an appearance, and the window actually exists as a rectangular window.
Therefore, by looking directly under the mouse cursor, if it is transparent, the mouse operation is passed to the window below (click-through), and if it is opaque, the mouse operation is returned to normal, If it is opaque, it returns to normal.

Two types of hit tests are available. (You can also choose to disable the automatic hit test and control it yourself or not.)

NameMethodNote
OpacityCheck transparencyMatches appearance and is natural, but heavy processing
RaycastCheck coliderLightweight, but requires coliders

The Raycast method is recommended in terms of performance, but if you forget colider, you will not be able to touch the screen, so the default is Opacity.

Also, note that touch operation may feel uncomfortable because you cannot see the color under your finger in advance.
Since we have not found the best solution for this, I'm sorry to say that touch support has been put on the back burner.

About the transparency method (Seceltable only on Windows)

One way to support touch operation is to select monochromatic transparency for layered windows.
If this is selected, semi-transparency cannot be expressed and performance will be reduced, but since the hit test is left to Windows, it should match your senses for touch operation.

NameDescriptionNote
AlphaReflects transparency of rendering resultsThis is standard
ColorKeyOnly one color with matching RGB is transparentPoor performance, but touch is natural

C# scripting

This is something that can be manipulated from other scripts in Unity.
Specifications are not finalized and are subject to change.

UniWindowController.cs

This is the main script. The following properties can be manipulated from other scripts. (Other properties may be added.)

NameTypeDescription
isTransparentboolSet/unset for transparent (non-rectangular) windows
isTopmostboolAlways set/unset to topmost
isZoomedboolMaximize/unmaximize the window. Also, get the current state
isHitTestEnabledboolEnables/disables the automatic hit test. If enabled, isClickThrough will automatically change depending on the mouse cursor position.
isClickThroughboolSets/unset the click-through state.
windowPositionVector2Allows you to get/set the window position. The lower left corner of the main monitor is the origin and the coordinate system is positive upward, and the lower left corner of the window is the coordinate system.
windowSizeVector2You can get/set the window size.

UniWindowMoveHandler.cs

If you attach this script to a UI element (which will be the Raycast Target), you can move the window by dragging that UI element. For example, it is assumed to be attached to an image with a handle that says, "You can move by grabbing here.

Within the prefab called DragMoveCanvas, we use a Panel that covers the entire transparent screen. By setting the Layer to "Ignore Raycast", the automatic hit test will be excluded even if the panel is a Raycast.
This allows dragging anywhere on the screen.
However, other UI operations will take precedence over dragging. (This is due to the smaller Sort Order in DragMoveCanvas.)

Source folder hierarchy

If you just want to use this library, you can download .unitypackage in Release and do not need to clone this repository.
If you want to see/build the source, please refer to this.

Acknowledgements

I would like to thank them.