Class SerenityUiContext
Shared helper that lets gameplay code build REAL Serenity themed UI components at runtime. It resolves
the active theme + required services from the service locator and constructs the Serenity component
factories (which aren't registered in the locator but only need the view-element factory). Reusable
foundation for the Widgets module.
Inheritance
SerenityUiContext
Assembly: Serenity.UnityUi.Infrastructure.dll
Syntax
public sealed class SerenityUiContext
Constructors
SerenityUiContext(IServiceLocator)
Declaration
public SerenityUiContext(IServiceLocator locator)
Parameters
Properties
IsReady
Declaration
public bool IsReady { get; }
Property Value
Log
Declaration
public ILogService Log { get; }
Property Value
Theme
Declaration
public IUiThemeDefinition Theme { get; }
Property Value
ThemeSounds
Declaration
public IUiThemeSounds ThemeSounds { get; }
Property Value
Methods
CreateButton(Transform, string, int, string, Action)
Creates a real Serenity button (theme Submittable) parented under parent.
onClick fires on mouse click or programmatic Submit().
Declaration
public SerenityButton CreateButton(Transform parent, string id, int index, string label, Action onClick)
Parameters
Returns
CreateGauge(Transform, string, int, string, float)
Creates a read-only fill gauge (0..1) from the theme's LoadingProgress component (a real Serenity
UnityUiSliderComponent), parented under parent.
Declaration
public SerenityGauge CreateGauge(Transform parent, string id, int index, string label, float initial01)
Parameters
Returns
CreateImage(Transform, Sprite)
Creates a plain gameplay image widget (portrait/icon/banner) parented under parent.
Declaration
public SerenityImage CreateImage(Transform parent, Sprite sprite = null)
Parameters
| Type |
Name |
Description |
| Transform |
parent |
|
| Sprite |
sprite |
|
Returns
CreateLabel(Transform, string, float)
Creates a themed text label from the theme's TitleTemplate prefab (inherits theme font/style),
parented under parent. The prefab's localization updater is disabled so the literal
text is shown verbatim.
Declaration
public SerenityLabel CreateLabel(Transform parent, string text, float fontSize = 0)
Parameters
| Type |
Name |
Description |
| Transform |
parent |
|
| string |
text |
|
| float |
fontSize |
|
Returns
CreateOptionComponent(string, int, string, bool)
Creates a fully-themed submit option for a host that drives focus/selection itself (e.g. the cascade
menu). Unlike CreateButton(Transform, string, int, string, Action) this preserves the theme look — it does NOT strip the
Highlight, animations or font — and runs the theme's decoration pass so the native highlight responds
to UnityUiSubmitComponent.SetFocus. The caller parents it and handles input.
Declaration
public UnityUiSubmitComponent CreateOptionComponent(string id, int index, string label, bool enabled)
Parameters
| Type |
Name |
Description |
| string |
id |
Stable id for the option component.
|
| int |
index |
Option index within its column.
|
| string |
label |
Literal label text (not localized here).
|
| bool |
enabled |
Whether the option is selectable (drives the themed disabled look).
|
Returns
| Type |
Description |
| UnityUiSubmitComponent |
The themed submit component, or null if the theme/factory is unavailable.
|
FromLocator()
Build a context from the static service locator, or null if Serenity isn't up yet.
Declaration
public static SerenityUiContext FromLocator()
Returns