Class FloatingWindow
A draggable, resizable window that floats above the rest of the UI and remembers where the user left it.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class FloatingWindow : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The window positions itself absolutely inside its parent, so give it a parent that fills the area you want it to roam. Its title bar is the drag handle and its bottom-right corner carries a ResizeHandle; both clamp the result so the whole window stays inside the parent rather than leaving a sliver on screen.
Geometry is persisted under storageKey through storage, which
defaults to PlayerPrefsWindowLayoutStorage — the platform-native counterpart of the
registry's window.localStorage default. Restoring re-clamps against the current container, so a
layout saved on a larger screen still comes back fully visible.
autoSize lets the content size the window and implies it is not resizable, matching the registry.
Not ported: the registry's Tab focus trap and its shared window stack (useWindowStack)
have no UI Toolkit counterpart here. Ordering between several floating windows is whatever their
order in the hierarchy gives you; bring one forward by re-adding it to its parent.
Examples
A tool window in UXML.
<appui:FloatingWindow title="Inspector" storage-key="inspector-window" open="true">
<appui:Text text="Anything you like goes here." />
</appui:FloatingWindow>
Opened from C#, with an injected store.
var window = new FloatingWindow
{
title = "Inspector",
storageKey = "inspector-window",
storage = myPreferencesAdapter,
defaultWidth = 360f,
defaultHeight = 480f,
};
window.Add(new Text { text = "Anything you like goes here." });
window.openChanged += isOpen => Debug.Log($"open: {isOpen}");
root.Add(window);
window.open = true;
Constructors
FloatingWindow()
Default constructor.
Declaration
public FloatingWindow()
Fields
autoSizeUssClassName
The styling class applied while autoSize is on.
Declaration
public const string autoSizeUssClassName = "appui-floating-window--auto-size"
Field Value
| Type | Description |
|---|---|
| string |
bodyUssClassName
The styling class of the body the content lives in.
Declaration
public const string bodyUssClassName = "appui-floating-window__body"
Field Value
| Type | Description |
|---|---|
| string |
closeButtonUssClassName
The styling class of the close button.
Declaration
public const string closeButtonUssClassName = "appui-floating-window__close-button"
Field Value
| Type | Description |
|---|---|
| string |
defaultMargin
The margin kept between a defaulted window and the container's bottom-right corner.
Declaration
public const float defaultMargin = 24
Field Value
| Type | Description |
|---|---|
| float |
defaultMinHeight
The default minimum window height, in pixels. Mirrors the registry.
Declaration
public const float defaultMinHeight = 240
Field Value
| Type | Description |
|---|---|
| float |
defaultMinWidth
The default minimum window width, in pixels. Mirrors the registry.
Declaration
public const float defaultMinWidth = 320
Field Value
| Type | Description |
|---|---|
| float |
defaultWindowHeight
The default window height, in pixels. Mirrors the registry.
Declaration
public const float defaultWindowHeight = 600
Field Value
| Type | Description |
|---|---|
| float |
defaultWindowWidth
The default window width, in pixels. Mirrors the registry.
Declaration
public const float defaultWindowWidth = 420
Field Value
| Type | Description |
|---|---|
| float |
headerUssClassName
The styling class of the title bar, which is also the drag handle.
Declaration
public const string headerUssClassName = "appui-floating-window__header"
Field Value
| Type | Description |
|---|---|
| string |
resizeHandleUssClassName
The styling class of the bottom-right resize grip.
Declaration
public const string resizeHandleUssClassName = "appui-floating-window__resize-handle"
Field Value
| Type | Description |
|---|---|
| string |
titleUssClassName
The styling class of the title text.
Declaration
public const string titleUssClassName = "appui-floating-window__title"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The FloatingWindow main styling class.
Declaration
public const string ussClassName = "appui-floating-window"
Field Value
| Type | Description |
|---|---|
| string |
Properties
autoSize
Whether the window sizes itself to its content instead of to a fixed box.
Declaration
[Tooltip("Whether the window sizes itself to its content.")]
[CreateProperty]
[UxmlAttribute]
public bool autoSize { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
This implies not resizable, and neither the width nor the height is persisted while it is on.
contentContainer
Logical container where child elements are added. If a child is added to this element, the child is added to this element's content container instead.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
defaultHeight
The height the window opens at when nothing has been persisted, in pixels.
Declaration
[Tooltip("The height the window opens at when nothing has been persisted.")]
[CreateProperty]
[UxmlAttribute]
public float defaultHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
defaultWidth
The width the window opens at when nothing has been persisted, in pixels.
Declaration
[Tooltip("The width the window opens at when nothing has been persisted.")]
[CreateProperty]
[UxmlAttribute]
public float defaultWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
defaultX
The x the window opens at when nothing has been persisted. NaN (the default) places it
against the container's right edge.
Declaration
public float defaultX { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
defaultY
The y the window opens at when nothing has been persisted. NaN (the default) places it
against the container's bottom edge.
Declaration
public float defaultY { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
dismissable
Whether the title bar shows a close button.
Declaration
[Tooltip("Whether the title bar shows a close button.")]
[CreateProperty]
[UxmlAttribute]
public bool dismissable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
layoutGeometry
The geometry the window is currently at, in pixels relative to its parent.
Declaration
public WindowLayout layoutGeometry { get; }
Property Value
| Type | Description |
|---|---|
| WindowLayout |
layoutResolved
Whether the window has resolved a geometry yet, either restored or defaulted.
Declaration
public bool layoutResolved { get; }
Property Value
| Type | Description |
|---|---|
| bool |
minHeight
The smallest height the resize grip will produce, in pixels.
Declaration
[Tooltip("The smallest height the resize grip will produce.")]
[CreateProperty]
[UxmlAttribute]
public float minHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
minWidth
The smallest width the resize grip will produce, in pixels.
Declaration
[Tooltip("The smallest width the resize grip will produce.")]
[CreateProperty]
[UxmlAttribute]
public float minWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
open
Whether the window is currently shown.
Declaration
[Tooltip("Whether the window is currently shown.")]
[CreateProperty]
[UxmlAttribute]
public bool open { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Opening restores the persisted geometry, or falls back to the defaults when there is none. Closing only hides the window; the geometry stays saved.
resizable
Whether the bottom-right resize grip is shown. Ignored while autoSize is on.
Declaration
[Tooltip("Whether the bottom-right resize grip is shown.")]
[CreateProperty]
[UxmlAttribute]
public bool resizable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
storage
The persistence backend. Defaults to instance.
Declaration
public IWindowLayoutStorage storage { get; set; }
Property Value
| Type | Description |
|---|---|
| IWindowLayoutStorage |
Remarks
Set this to null to fall back to the default. Set it to an in-memory implementation in
tests, or to your own adapter to route the layout into an existing preference store.
storageKey
The key the geometry is persisted under.
Declaration
[Tooltip("The key the window geometry is persisted under.")]
[CreateProperty]
[UxmlAttribute]
public string storageKey { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Give every window in your app its own key, or two windows will fight over one saved layout.
title
The window's title. Accepts a localization key.
Declaration
[Tooltip("The window's title.")]
[CreateProperty]
[UxmlAttribute]
public string title { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
ResetLayout()
Forgets the persisted geometry and returns the window to its defaults.
Declaration
public void ResetLayout()
RestoreLayout()
Restores the persisted geometry, falling back to the defaults when there is none.
Declaration
public void RestoreLayout()
Remarks
The restored geometry is re-clamped against the current container size and the current minWidth / minHeight, so a layout saved on a larger screen comes back fully visible rather than off-screen.
SaveLayout()
Writes the current geometry to storage under storageKey.
Declaration
public void SaveLayout()
Remarks
This runs automatically at the end of a drag or a resize. Call it directly only if you move the window by setting its style yourself.
Events
openChanged
Raised when open changes.
Declaration
public event Action<bool> openChanged
Event Type
| Type | Description |
|---|---|
| Action<bool> |