logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    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
    object
    SerenityUiContext
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    Namespace: Serenity.Ui.Infrastructure.Widgets
    Assembly: Serenity.UnityUi.Infrastructure.dll
    Syntax
    public sealed class SerenityUiContext

    Constructors

    SerenityUiContext(IServiceLocator)

    Declaration
    public SerenityUiContext(IServiceLocator locator)
    Parameters
    Type Name Description
    IServiceLocator locator

    Properties

    IsReady

    Declaration
    public bool IsReady { get; }
    Property Value
    Type Description
    bool

    Log

    Declaration
    public ILogService Log { get; }
    Property Value
    Type Description
    ILogService

    Theme

    Declaration
    public IUiThemeDefinition Theme { get; }
    Property Value
    Type Description
    IUiThemeDefinition

    ThemeSounds

    Declaration
    public IUiThemeSounds ThemeSounds { get; }
    Property Value
    Type Description
    IUiThemeSounds

    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
    Type Name Description
    Transform parent
    string id
    int index
    string label
    Action onClick
    Returns
    Type Description
    SerenityButton

    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
    Type Name Description
    Transform parent
    string id
    int index
    string label
    float initial01
    Returns
    Type Description
    SerenityGauge

    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
    Type Description
    SerenityImage

    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
    Type Description
    SerenityLabel

    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
    Type Description
    SerenityUiContext
    In this article
    © 2026 Serenity. All Rights Reserved