Represents a theme data asset for configuring and managing window frame themes in the Window Framework system. This class is a ScriptableObject that provides functionality for managing themes, tracking the active theme, and applying changes to the window frame styles.
More...
|
| void | CleanPlayerThemes () |
| | The beginigs of a method to load player themes from the persistent data path. However, Unity does not currently support loading stylesheets at runtime from the persistent data path. I can not imagine this being the case for much longer so i have left this in place and will update it when Unity allows this.
|
| delegate void | DefaultThemeChangedEventHandler (int newThemeIndex) |
| | Event that is raised when the default theme designation changes.
|
| void | EnsureDefaultStyleSheets () |
| | Placeholder method for future player theme functionality - ensures default stylesheets exist in persistent storage. Creates directories and copies default theme stylesheets to the persistent data path for player modification.
|
| void | LoadPlayerThemes () |
| | Placeholder method for future player theme functionality - loads player-created themes from persistent storage. Scans the persistent data path for player theme directories and attempts to load theme files.
|
| void | SetAsDefaultTheme (int themeIndex) |
| | Designates a specific theme as the default theme by clearing the default flag from all themes and setting it only on the specified theme index. Triggers the default theme changed event to notify subscribers.
|
| void | SetTheme (int newActiveThemeIndex) |
| | Updates the active theme by setting the specified theme index. If the provided index is invalid or out of range, a default theme index is applied instead. Upon successful update of the active theme, triggers the OnThemeChanged event to notify listeners about the theme change.
|
| void | SetToDefaultTheme () |
| | Configures the theme list to ensure a default theme is set. If no default theme is already specified, the first theme in the list is assigned as the default. If a default theme exists, it ensures the active theme index is updated accordingly. Logs warnings or errors if the theme list is empty or no default theme is found. Triggers the theme changed event upon successful theme configuration.
|
| delegate void | ThemeChangedEventHandler (int newThemeIndex, StyleSheet newStylesheet) |
| | Event that is raised when the active theme changes.
|
|
| int | ActiveThemeIndex [get, set] |
| | Represents the index of the currently active theme within the list of available themes. This property is used to determine which theme's stylesheet is applied to the window frame. When set, it validates the provided index to ensure it falls within the valid range of the theme list. Changes to this property trigger notifications to reflect updates in the theme selection.
|
| StyleSheet | CurrentStylesheet [get] |
| | Gets the current active stylesheet based on the selected theme in the theme list. This property dynamically determines which theme's StyleSheet should be returned by evaluating the active theme index and ensuring it points to a valid theme. If the active theme index is invalid or out of range, it will attempt to find a default theme or set the first theme in the list as the default. Returns null if no themes are available.
|
| ThemeApplyMethods | ThemeApplyMethod [get, set] |
| | Defines the method used to apply themes in the window framework. Determines the scope of the theme application, ranging from targeting only window frames to applying the theme to broader groups such as parent panels or all active panels in the scene.
|
| List< WindowFrameTheme > | Themes [get, set] |
| | Represents a collection of themes used to manage and apply different stylesheets for the window framework. This list enables dynamic switching between themes at runtime and provides a structured way to handle theme data in the inspector.
|
The WindowFrameThemeData class serves as the central hub for theme management within the Window Framework. It handles theme loading, validation, switching, and application across different scopes of the user interface.
Key Features:
-
Dynamic theme switching at runtime
-
Automatic default theme handling and validation
-
Event-driven theme change notifications
-
Configurable theme application methods
-
Built-in default theme fallback system
-
Future support for player-created themes
This class includes the ability to load and manage themes bundled with the application. It also provides methods to apply themes and invoke changes when the active theme is updated.
Integration:
This class implements INotifyPropertyChanged for editor integration and real-time property updates, making it suitable for both runtime and editor-time theme management scenarios.
{
name = "Dark Theme",
themeStyleSheet = darkThemeStyleSheet,
isDefault = false
};
themeData.Themes.Add(customTheme);
themeData.SetTheme(1);
themeData.OnThemeChanged += (index, stylesheet) =>
{
Debug.Log($"Theme changed to index {index}");
ApplyThemeToUI(stylesheet);
};
Represents a theme data asset for configuring and managing window frame themes in the Window Framewor...
Definition WindowFrameThemeData.cs:141
Definition WindowFrameTheme.cs:9
ThemeApplyMethods
Specifies the method used to apply themes within the window framework system. Determines the level or...
Definition WindowFrameThemeData.cs:67
| void GWG.WindowFramework.WindowFrameThemeData.SetTheme |
( |
int | newActiveThemeIndex | ) |
|
- Parameters
-
| newActiveThemeIndex | The index of the theme to be set as active. |
This method is the primary way to switch themes in the window framework. It performs validation on the provided index and updates the active theme accordingly. If the index is invalid, it falls back to the first theme (index 0).
Event Notification:
Upon successful theme change, the method triggers the OnThemeChanged event with the new theme index and associated StyleSheet, allowing subscribers to update their UI elements accordingly.
themeData.SetTheme(2);
int desiredTheme = 4;
if (desiredTheme < themeData.Themes.Count)
{
themeData.SetTheme(desiredTheme);
Debug.Log($"Switched to theme: {themeData.Themes[desiredTheme].name}");
}
int nextTheme = (themeData.ActiveThemeIndex + 1) % themeData.Themes.Count;
themeData.SetTheme(nextTheme);
string targetTheme = "Dark Mode";
int themeIndex = themeData.Themes.FindIndex(t => t.name == targetTheme);
if (themeIndex >= 0)
{
themeData.SetTheme(themeIndex);
Debug.Log($"Switched to theme: {targetTheme}");
}
private void OnThemeDropdownChanged(int selectedIndex)
{
themeData.SetTheme(selectedIndex);
PlayerPrefs.SetInt("UserSelectedTheme", selectedIndex);
PlayerPrefs.Save();
}
A List<T> of WindowFrameTheme objects representing all available themes that can be applied to the window framework.
This collection serves as the central repository for all theme configurations within the window framework. It supports dynamic modification at runtime and provides the foundation for theme switching functionality.
Collection Integrity:
The framework ensures that at least one theme is always available and that exactly one theme is designated as the default theme. Invalid configurations are automatically corrected during initialization.
{
name = "Custom Dark Theme",
themeStyleSheet = customStyleSheet,
isDefault = false
};
themeData.Themes.Add(newTheme);
var darkTheme = themeData.Themes.Find(t => t.name.Contains("Dark"));
if (darkTheme != null)
{
Debug.Log($"Found dark theme: {darkTheme.name}");
}
for (int i = 0; i < themeData.Themes.Count; i++)
{
var theme = themeData.Themes[i];
Debug.Log($"Theme {i}: {theme.name} (Default: {theme.isDefault})");
}