Comment on page
Window System
Easily manage in game windows, panels and dialogs.
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude.
These articles are made possible by our GitHub Sponsors ... become a sponsor today!
The Window system makes it easy to define drag-able, re-sizable and dock-able windows in your game. The simple system can be attached to any Rect Transform and supports all canvas modes and all anchoring types. Window groups can be defined easily by simply parenting them in there own Rect Transforms where windows focus (move to top) and clamp (remain in frame) according to there parent.
Check out the following articles for more details on specific components

With this system, you have complete control of your window's features including resize and move handles. You can choose to add a move handle, allowing the window to be dragged around the parent, rather or not it clamps to the parent and rather or not it remains always on top of other windows.

The API.Windows interface makes it easy to search for and manage all available windows and identify the currently focused window. Windows use the Selectable Tag system meaning you can tag your windows with multiple tags and search for windows with matching tags.

Intended to be added to a child object of your window the RecTransform this is added to will be the clickable area that when clicked allows the user to drag the window.

Similar to the Move Handle, the Border Handle is intended to be added to a child object of your window, the RectTransform of which will be the clickable area that when click allows the user to drag to resize the window. Border Handles need to be told what part of the border they are on as this effects the drag to resize behaviour.
- Top Drag increases the height of the window from its top edge
- Bottom Drag increases the height of the window from its bottom edge
- Left Drag increases the width of the window from its left edge
- Right Drag increases the window of the window from its right edge
- Upper Left Drag increases the height and width of the window from its upper left corner
- Upper Right Drag increases the height and width of the window from its upper right corner
- Lower Left Drag increases the height and width of the window from its lower left corner
- Lower Right Drag increases the height and width of the window from its lower right corner
public static Window focused;
You can get the Window object that is currently focused from the static focused attribute.
var focusedWindow = Window.focused;
This assumes the window you wish to give focus to is named
targetWindow
This set the target window as the Window.focused and moves the window to be on top of non-Always On Top windows.
targetWindow.Focus();
This example assumes the window to be moved is named
targetWindow
and that you wish to move it to a location defined as position
//Get the position
position = targetWindow.Position;
//Set the position
targeWindow.Position = position;
This respects the "anchor" you set in Unity's Rect Transform. For example if you want the window to move relative to its upper left corner then you should set the anchor position of its Rect Transform to the upper left corner.
This example assumes the window to be sized is named
targetWindow
and that you wish to set its size to a value defined as width
//Get the width
width = targetWindow.Width;
//Set the width
targetWindow.Width = width;
This respects the "anchor" you set in Unity's Rect Transform. For example if you want the window to move relative to its upper left corner then you should set the anchor position of its Rect Transform to the upper left corner.
This example assumes the window to be sized is named
targetWindow
and that you wish to set its size to a value defined as height
//Get the height
height = targetWindow.Height;
//Set the height
targetWindow.Height = height;
This respects the "anchor" you set in Unity's Rect Transform. For example if you want the window to move relative to its upper left corner then you should set the anchor position of its Rect Transform to the upper left corner.
This will set the windows position and size at the same time.
targetWindow.SetTransform(size, position);
This will snap the window to the position and size of the input RectTransform.
Scale is not accounted for in this operation. Its advised that you dock to transforms that in the same canvas or otherwise are at the same global scale as the window.
targetWindow.DockTo(targetRect);
Last modified 5mo ago