|
Window Framework v1.2.4
Window Framework for Unity UI Toolkit
|
The WindowFrameController is the central management component for the Window Framework system. It serves as a singleton that manages window frames, themes, tooltips, context menus, and persistent data. More...
Public Member Functions | |
| void | AddOrUpdateWindowData (string dataKey, WindowFrameData windowData) |
| Updates or adds window configuration data for persistence. | |
| List< StyleSheet > | BuildSheetList () |
| Builds a complete list of stylesheets for the current theme configuration. | |
| void | ClearPreferences (bool forceAll=false) |
| Clears all framework preferences and window memory, resetting everything to defaults. | |
| WindowFrameData | GetWindowData (string dataKey) |
| Retrieves window configuration data by its unique identifier. | |
| void | OpenSettingsWindow () |
| Opens the built-in settings window for configuring the window framework. | |
| void | ReopenWindows (float delay=0.1f) |
| Restores previously opened windows from saved data after a specified delay. | |
| void | ReopenWindowsInternal () |
| Performs the actual window restoration from saved data. | |
| void | ResetSettings () |
| Resets all framework settings to their default values while preserving window memory data. | |
| void | SetActiveWindow (WindowFrame newTarget) |
| Sets the specified window as the active window and deactivates all others. | |
Static Public Member Functions | |
| static void | AddElement (VisualElement newElement) |
| Adds a visual element to the window framework's root element with special handling for WindowFrame instances. | |
| static void | ApplyTooltips () |
| Applies tooltip functionality to all UI elements based on current theme settings. | |
| static void | ApplyTooltips (VisualElement root) |
| Applies tooltip manipulators to UI elements within the specified root element. | |
Public Attributes | |
| VisualElement | RootElement |
| The root VisualElement that serves as the primary container for all UI elements. | |
| WindowFrameThemeData | themeData |
| The theme data configuration for the window framework. | |
| Dictionary< string, WindowFrameData > | WindowFrameSettingsData = new Dictionary<string, WindowFrameData>() |
| Dictionary storing configuration data for each window frame. | |
Properties | |
| int | ActiveThemeIndex [get] |
| Gets the index of the currently active theme. | |
| List< WindowFrame > | ActiveWindowFrames [get] |
| Gets a list of all currently active window frames in the framework. | |
| int | ContextMenuDelay [get, set] |
| [DEPRECATED] Gets or sets the delay before a context menu is displayed. | |
| float | ContextMenuFadeDelay [get, set] |
| Gets or sets the delay before context menus begin fading out. | |
| float | ContextMenuFadeTime [get, set] |
| Gets or sets the duration of context menu fade-out animations. | |
| StyleSheet | CurrentStylesheet [get] |
| Gets the primary stylesheet for the current theme. | |
| List< StyleSheet > | CurrentThemeStylesheets [get] |
| Gets the current list of stylesheets based on active theme settings. | |
| StyleSheet | DefaultStylesheet [get, set] |
| Gets or sets the default stylesheet used when themes are not enabled or set. | |
| VisualElement | GhostIcon [get, set] |
| GlobalsLoadOrder | GlobalsLoadOrder [get, set] |
| Gets or sets the loading order for global stylesheet relative to theme stylesheets. | |
| StyleSheet | GlobalStylesheet [get, set] |
| Gets or sets the global stylesheet applied across all themes. | |
| static WindowFrameController | Instance [get, private set] |
| Gets the singleton instance of the WindowFrameController. | |
| bool | MemoryEnabled [get, set] |
| Gets or sets whether the framework should persist window states and settings. | |
| int | TooltipDelay [get, set] |
| [DEPRECATED] Gets or sets the delay before a tooltip is shown or hidden. | |
| float | TooltipFadeDelay [get, set] |
| Gets or sets the delay before tooltips begin fading out. | |
| float | TooltipFadeTime [get, set] |
| Gets or sets the duration of tooltip fade animations. | |
| TooltipFadeType | TooltipFadeType [get, set] |
| Gets or sets the type of fade animation for tooltips. | |
| bool | TooltipsActive [get, set] |
| Gets or sets whether tooltips are active and functional. | |
| float | TooltipShowDelay [get, set] |
| Gets or sets the delay before showing tooltips when hovering over elements. | |
| static VisualElement | UIRoot [get] |
| Gets the root VisualElement for the window framework's UI hierarchy. | |
| static WindowFrameTooltip | WindowFrameTooltip [get, set] |
| Gets or sets the static tooltip system instance. | |
Events | |
| static Action< List< StyleSheet >, List< StyleSheet > > | OnThemeChanged |
| Event triggered when the application theme changes. | |
Private Member Functions | |
| void | AddGhostIcon () |
| [EXPERIMENTAL] Creates and configures the ghost icon for drag operations. | |
| void | ApplyThemeToPanel (IPanel panel, List< StyleSheet > sheets) |
| Applies a list of stylesheets to a specific UI panel. | |
| void | Awake () |
| Initializes the WindowFrameController instance during Unity's Awake phase. | |
| WindowFrame | FindActiveWindowFrame () |
| Finds and returns the first active window frame. | |
| WindowFrame | FindFormostWindowFrame () |
| Finds and returns the foremost (top-level) window frame in the UI hierarchy. | |
| void | HandleThemeChanged (int newThemeIndex, StyleSheet newStylesheet) |
| Handles theme change events and applies new stylesheets based on theme configuration. | |
| void | HandleWindowFrameAdded (WindowFrame window) |
| Handles the event when a new WindowFrame is added to the framework. | |
| void | HandleWindowFrameRemoved (WindowFrame window) |
| Handles the event when a WindowFrame is removed from the framework. | |
| void | LoadWindowFrameworkData () |
| Loads window framework configuration data from persistent storage. | |
| void | OnDestroy () |
| Handles cleanup and data persistence when the component is destroyed. | |
| void | OnDisable () |
| Unsubscribes from events when the component is disabled. | |
| void | OnEnable () |
| Subscribes to events and performs initialization when the component is enabled. | |
| System.Collections.IEnumerator | ReopenWindowsDelayed (float delay=0.1f) |
| Internal coroutine that handles delayed window restoration. | |
| void | SaveWindowFrameworkData () |
| Saves current window framework configuration data to persistent storage. | |
| void | SetActiveWindowDelayed (WindowFrame newTarget, int delay=5) |
| Sets the active window after a specified delay. | |
| void | SetDefaultValues () |
| Sets all configurable values to their default constants. | |
| void | Update () |
| Updates the controller state each frame during Unity's Update phase. | |
Private Attributes | |
| List< StyleSheet > | _appliedStylesheets = new List<StyleSheet>() |
| Internal list tracking currently applied stylesheets for theme management. | |
| InputAction | _clickAction |
| Input action for handling click events within the window framework. | |
| VisualElement | _ghostIcon |
| [EXPERIMENTAL] The ghost icon element used for drag-and-drop operations. | |
| float | contextMenuFadeDelay = ContextMenuFadeDelayDefault |
| float | contextMenuFadeTime = ContextMenuFadeTimeDefault |
| string | dataFileName = "WindowFrameData.json" |
| The filename for storing window framework data in the persistent data folder. | |
| StyleSheet | defaultStyleSheet |
| GlobalsLoadOrder | globalsLoadOrder |
| StyleSheet | globalStyleSheet |
| bool | memoryEnabled = true |
| float | tooltipFadeDelay = TooltipFadeDelayDefault |
| float | tooltipFadeTime = TooltipFadeTimeDefault |
| TooltipFadeType | tooltipFadeType = TooltipFadeType.FadeOut |
| bool | tooltipsEnabled = true |
| float | tooltipShowDelay = TooltipShowDelayDefault |
| UIDocument | uiDocument |
| The primary UIDocument component attached to this GameObject. | |
| List< UIDocument > | uiDocuments = new List<UIDocument>() |
| A collection of additional UIDocument components managed by this controller. | |
Static Private Attributes | |
| static WindowFrameTooltip | _windowFrameTooltip |
| const float | ContextMenuFadeDelayDefault = 0.75f |
| Default delay before context menu fades (in seconds). | |
| const float | ContextMenuFadeTimeDefault = 0.5f |
| Default context menu fade animation duration (in seconds). | |
| const bool | MemoryEnabledDefault = true |
| Default state for memory/persistence system. | |
| const float | TooltipFadeDelayDefault = 0.75f |
| Default delay before fading tooltips (in seconds). | |
| const float | TooltipFadeTimeDefault = 0.5f |
| Default tooltip fade animation duration (in seconds). | |
| const TooltipFadeType | TooltipFadeTypeDefault = TooltipFadeType.FadeInAndOut |
| Default tooltip fade behavior. | |
| const bool | TooltipsEnabledDefault = true |
| Default state for tooltip system. | |
| const float | TooltipShowDelayDefault = 2 |
| Default delay before showing tooltips (in seconds). | |
This component should be attached to a GameObject with a UIDocument component. It automatically handles initialization, event subscriptions, and cleanup operations.
Key Features:
The controller persists across scene loads using DontDestroyOnLoad.
|
static |
| newElement | The VisualElement to add to the framework |
This method provides intelligent element addition with special logic for WindowFrame elements:
For WindowFrame elements:
For other VisualElements:
This prevents unintended window duplication while allowing multiple instances when desired.
|
private |
⚠️ EXPERIMENTAL FEATURE: This method sets up a ghost icon element that can be used for drag-and-drop operations between windows, toolbars, or other UI elements.
The ghost icon is initially hidden and positioned absolutely to follow mouse movement during drag operations. It's semi-transparent to provide visual feedback without obscuring the drop target.
Configuration details:
This is not officially supported and the implementation may change.
| void GWG.WindowFramework.WindowFrameController.AddOrUpdateWindowData | ( | string | dataKey, |
| WindowFrameData | windowData ) |
| dataKey | Unique identifier for the window data, typically formatted as [Type]_[ParentObjectId]_[WindowId] |
| windowData | WindowFrameData object containing window state information |
This method manages the window data dictionary that persists window states across application sessions. The data is only stored if MemoryEnabled is true.
The dataKey should be unique for each window instance and follow the format: [WindowType]_[ParentObjectId]_[WindowId]
The windowData contains information such as:
|
private |
| panel | The target panel to apply stylesheets to |
| sheets | List of stylesheets to apply |
This method safely applies stylesheets to a panel by:
The method ensures clean theme transitions by removing old styles before applying new ones, preventing style accumulation and conflicts.
|
static |
This overload automatically determines the scope of tooltip application based on the theme's apply method configuration:
Call this method after theme changes or when initializing the framework to ensure all UI elements have proper tooltip support.
|
static |
| root | The parent VisualElement containing child elements that may need tooltips. |
This method should be called whenever new UI content is instantiated to ensure tooltip functionality is properly attached. It automatically detects elements with tooltip text and adds the necessary manipulators.
The method prevents duplicate manipulators by checking element userData and only operates when tooltips are enabled in the framework.
|
private |
This method implements the singleton pattern, ensuring only one instance exists. It performs the following initialization steps:
If multiple WindowFrameController components exist, only the first one becomes the singleton instance; others are automatically destroyed.
| List< StyleSheet > GWG.WindowFramework.WindowFrameController.BuildSheetList | ( | ) |
This method constructs the final stylesheet list by:
The order affects CSS cascade priority - later stylesheets can override earlier ones where there are conflicts.
| void GWG.WindowFramework.WindowFrameController.ClearPreferences | ( | bool | forceAll = false | ) |
| forceAll | If true, forces closure of all windows including locked ones. |
This method performs a complete reset of the framework:
This is more destructive than ResetSettings() as it also removes window position memory and closes active windows.
|
private |
This method searches through all WindowFrame elements in the RootElement and returns the first one that has its Active property set to true.
Used internally for window management operations that need to identify the currently active window. Returns null if no windows are active.
|
private |
This method determines which window appears on top by finding the last WindowFrame in the child order of the RootElement. In UI Toolkit, later children appear in front of earlier children.
Used when determining which window should be active when no specific target is provided to SetActiveWindow().
| WindowFrameData GWG.WindowFramework.WindowFrameController.GetWindowData | ( | string | dataKey | ) |
| dataKey | Unique identifier for the window data, typically formatted as [Type]_[ParentObjectId]_[WindowId] |
This method retrieves previously saved window data for restoration purposes. Returns null if:
The dataKey should match the format used when storing data: [WindowType]_[ParentObjectId]_[WindowId]
|
private |
| newThemeIndex | Index of the new theme being applied |
| newStylesheet | Primary stylesheet of the new theme |
This method responds to theme change events by:
The method ensures proper cleanup of previous stylesheets before applying new ones.
|
private |
| window | The WindowFrame instance that was added |
This event handler is automatically called when any WindowFrame is added to the UI hierarchy. It performs the following actions:
The delayed BringToFront() call ensures proper visual layering after the UI framework has processed the window addition.
|
private |
| window | The WindowFrame instance that was removed |
This event handler is automatically called when any WindowFrame is removed from the UI hierarchy. It performs cleanup operations:
The cleanup ensures that UI state remains consistent after window removal and prevents references to destroyed windows.
|
private |
This method attempts to load saved data from a JSON file in the persistent data path. The loaded data includes:
If the file doesn't exist or loading fails, default values are applied. The method gracefully handles corruption or missing data by falling back to defaults.
|
private |
This method performs comprehensive cleanup operations:
The cleanup ensures that user preferences and window states are preserved across application sessions while properly releasing all resources.
|
private |
This method prevents memory leaks and unintended behavior by properly unsubscribing from all event handlers when the component becomes inactive.
Events unsubscribed include:
This is essential for proper cleanup in Unity's component lifecycle.
|
private |
This method handles the following initialization tasks:
The method ensures proper event subscription for theme management and validates essential configuration to prevent runtime errors.
| void GWG.WindowFramework.WindowFrameController.OpenSettingsWindow | ( | ) |
The settings window allows users to adjust:
The settings window is a WindowFrame instance and follows the same behavior patterns as other framework windows.
| void GWG.WindowFramework.WindowFrameController.ReopenWindows | ( | float | delay = 0::1f | ) |
| delay | Delay in seconds before beginning window restoration. Default: 0.1f |
This method should be called at an appropriate point during application startup when you want saved windows to be restored. The delay allows the UI framework and other systems to fully initialize before creating window instances.
Only windows that were open when the application last closed will be restored, and only if MemoryEnabled is true. Window positions, sizes, and other properties are restored from the saved data.
|
private |
| delay | Delay in seconds before calling ReopenWindowsInternal. |
This coroutine provides the delay mechanism for ReopenWindows(). It waits for the specified time period, then calls ReopenWindowsInternal() to perform the actual window restoration logic.
The delay is essential to ensure that:
| void GWG.WindowFramework.WindowFrameController.ReopenWindowsInternal | ( | ) |
This method recreates window instances from saved WindowFrameSettingsData:
Window types must be accessible via Type.GetType() for restoration to work. If a window type is not found, a warning is logged and that window is skipped.
| void GWG.WindowFramework.WindowFrameController.ResetSettings | ( | ) |
This method resets the following settings to their default values:
Window position and size data in WindowFrameSettingsData is preserved, allowing users to reset preferences without losing window arrangements.
|
private |
This method serializes the current framework state to JSON format and saves it to the persistent data path. The saved data includes:
The save operation is automatically performed during component destruction to ensure user preferences persist across application sessions.
| void GWG.WindowFramework.WindowFrameController.SetActiveWindow | ( | WindowFrame | newTarget | ) |
| newTarget | The window frame to set as active. If null, the foremost window is activated. |
This method manages window focus and visual state:
Active windows typically receive different styling (via CSS) to indicate focus. Only one window should be active at a time to provide clear user feedback.
|
private |
| newTarget | The window to activate. |
| delay | Delay in milliseconds before activation. Default: 5ms |
This method uses Unity's scheduling system to delay window activation, allowing the UI to complete any pending updates before changing focus.
The delay is typically very short (5ms) and is used to ensure proper timing in the UI update cycle, especially after window creation or modification operations.
|
private |
This private method initializes or resets all framework settings to the default values defined by constants at the top of the class:
Called during initialization when no saved data exists, or when loading saved data fails, or when explicitly resetting settings.
|
private |
This method performs the following maintenance tasks:
The method only operates during play mode to avoid edit-mode errors. It handles edge cases where UI components might be destroyed or reassigned.
|
private |
Used internally to track which stylesheets are currently applied to panels so they can be properly removed when themes change.
|
private |
This action is used internally to manage UI interactions and window focus changes. It's automatically configured during the controller's initialization.
|
private |
A VisualElement representing a draggable ghost icon, or null if not active.
⚠️ EXPERIMENTAL FEATURE: This is not a supported feature and is provided only as an example of how to implement icon dragging between windows or toolbars.
The ghost icon provides visual feedback during drag operations, showing a semi-transparent representation of the item being dragged. This can be used with custom drag manipulators to create rich drag-and-drop interactions.
Use at your own risk - this API may change or be removed in future versions.
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
The name of the JSON file where window and framework settings are stored. Default: "WindowFrameData.json"
This file is created in Application.persistentDataPath and contains:
Change this value if you need to use a different filename or want to separate data for different game modes or users.
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
| VisualElement GWG.WindowFramework.WindowFrameController.RootElement |
This element is automatically assigned from the attached UIDocument component during initialization. It acts as the parent container for all window frames, tooltips, and other UI components managed by the framework.
| WindowFrameThemeData GWG.WindowFramework.WindowFrameController.themeData |
This ScriptableObject contains all theme definitions, stylesheets, and theme switching logic. When assigned, it enables dynamic theme switching and provides the current theme's stylesheets. If not assigned, the framework falls back to using the default stylesheet.
|
private |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
This component provides the root visual element and is automatically retrieved if not assigned. The UIDocument component is required for the WindowFrameController to function properly.
|
private |
These documents can be used for managing multiple UI panels or documents within the framework. Useful for complex UI setups with multiple documents that need coordinated theme management.
| Dictionary<string, WindowFrameData> GWG.WindowFramework.WindowFrameController.WindowFrameSettingsData = new Dictionary<string, WindowFrameData>() |
A dictionary where keys are window identifiers and values are WindowFrameData objects containing window settings, position, size, and state information.
This data is used for persistence across application sessions when memory is enabled. The key format is typically: [WindowType]_[ParentObjectId]_[WindowId]
The dictionary is automatically populated from saved data during initialization and updated during runtime as windows are modified.
|
get |
The zero-based index of the active theme from the theme data. Returns 0 if no theme data is assigned.
|
get |
A list of WindowFrame instances currently present in the UI hierarchy. The list is dynamically generated from the current UI state.
This property queries the UI hierarchy in real-time, so the returned list reflects the current state of active windows. The list may change between calls as windows are opened and closed.
|
getset |
The delay in milliseconds before context menu appearance.
This property is deprecated and will be removed in future versions. Use ContextMenuFadeDelay instead.
|
getset |
The delay in seconds before context menu fade-out begins after mouse leaves the menu area. Range: 0 to 5 seconds.
Context menus close immediately on click regardless of this setting. This delay allows users to temporarily move the mouse outside the menu without it disappearing immediately, improving usability.
|
getset |
The duration in seconds for context menu fade-out animation. Range: 0 to 3 seconds.
Context menus appear instantly; this only affects fade-out timing. Controls how smoothly context menus disappear when closing. Set to 0 for instant disappearance.
|
get |
The main StyleSheet object for the currently active theme. Returns the default stylesheet if no theme data is configured.
This property provides quick access to the main theme stylesheet without including global or additional stylesheets. Use CurrentThemeStylesheets if you need the complete list including global styles.
|
get |
A list of StyleSheet objects representing the current theme's styling. Includes the base theme stylesheet and global stylesheet based on load order settings.
If no theme data is available, returns a list containing only the default stylesheet. The order of stylesheets in the list affects CSS cascade and style precedence.
|
getset |
The StyleSheet object to use as fallback styling. This stylesheet is applied when no theme data is available.
This serves as the fallback styling for the framework when theme support is disabled or no specific theme is selected. It ensures that UI elements always have basic styling available.
|
getset |
|
getset |
A GlobalsLoadOrder value determining whether global styles are applied before (First) or after (Last) theme-specific stylesheets.
This setting affects CSS cascade and style precedence:
Choose based on whether you want themes to be able to override your global styling or vice versa.
|
getset |
A StyleSheet that is always applied regardless of the current theme. Can be null if no global styling is needed.
The global stylesheet provides consistent styling elements that should appear the same across all themes. Its load order relative to theme stylesheets is controlled by the GlobalsLoadOrder property.
This is useful for defining common UI patterns, animations, or framework-specific styles that shouldn't change with themes.
|
staticgetprivate set |
The active WindowFrameController instance in the scene. Returns null if no instance exists.
This instance is automatically created when the first WindowFrameController component is initialized and persists across scene changes.
|
getset |
True to enable automatic saving and loading of window positions, sizes, and states. False to disable persistence features.
When enabled, the framework automatically:
Data is saved to the persistent data path in JSON format. Disabling this feature improves performance but loses state persistence.
|
getset |
The delay in milliseconds before tooltip behavior.
This property is deprecated and will be removed in future versions. Use TooltipShowDelay or TooltipFadeDelay instead.
|
getset |
The delay in seconds before tooltip fade-out animation begins. Range: 0 to 5 seconds.
This controls how long a tooltip remains fully visible before starting to fade away. Longer delays give users more time to read tooltip content. Set to 0 for immediate fade-out when hover ends.
|
getset |
The duration in seconds for fade-in and fade-out animations. Range: 0 to 3 seconds.
Determines how long fade animations take to complete. Shorter times create snappy animations, while longer times create smoother, more gradual transitions. Only applies when TooltipFadeType includes fade effects.
|
getset |
The TooltipFadeType enum value specifying fade behavior. Options include FadeIn, FadeOut, FadeInAndOut, or None.
Controls the visual appearance and disappearance of tooltips:
|
getset |
True if tooltips should be displayed and functional; false to disable tooltip system.
When set to false, existing tooltip manipulators remain but tooltips won't be shown. When set to true, automatically searches for and initializes the tooltip system.
The tooltip system is automatically initialized during framework startup but can be toggled on/off during runtime as needed.
|
getset |
The delay in seconds before a tooltip appears after mouse hover begins. Range: 0 to 5 seconds.
This delay prevents tooltips from appearing immediately on hover, reducing visual noise and only showing tooltips for deliberate hover actions. Shorter delays make tooltips more responsive but potentially more intrusive.
|
staticget |
The root container VisualElement for all UI components. Returns null if no instance exists.
This provides static access to the UI root without needing to reference the instance directly. All window frames and UI elements are added as children of this root element.
|
staticgetset |
The WindowFrameTooltip instance managing tooltip display and behavior. Returns null if tooltips are disabled or not initialized.
This provides static access to the tooltip system for displaying contextual help information. The tooltip instance is automatically created and managed by the WindowFrameController.
|
static |
The first parameter contains the new stylesheets to apply. The second parameter contains the previously applied stylesheets.
This event is useful for UI elements that need to respond to theme changes by updating their appearance or refreshing their styling.