logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityUiService

    Unity-specific UI service that manages UI themes, scaling, and event handling for the user interface system.

    Inheritance
    object
    UnityUiService
    Implements
    IUiService
    IService
    IFoundationSettings
    Namespace: Serenity.Ui.Infrastructure.Services
    Assembly: Serenity.UnityUi.Infrastructure.dll
    Syntax
    public class UnityUiService : MonoBehaviour, IUiService, IService, IFoundationSettings

    Constructors

    UnityUiService()

    Declaration
    public UnityUiService()

    Fields

    _guid

    Declaration
    protected string _guid
    Field Value
    Type Description
    string

    GUID for the UI service instance.

    _id

    Declaration
    protected string _id
    Field Value
    Type Description
    string

    Unique identifier for the UI service instance.

    Properties

    Guid

    GUID for the UI service instance.

    Declaration
    public string Guid { get; set; }
    Property Value
    Type Description
    string

    The GUID string

    Id

    Unique identifier for the UI service instance.

    Declaration
    public string Id { get; set; }
    Property Value
    Type Description
    string

    The unique identifier string

    LogService

    Declaration
    public ILogService LogService { get; set; }
    Property Value
    Type Description
    ILogService

    Methods

    ApplyCurrentFontSizeToRoot(GameObject)

    Applies the current font size to all TMP_Text components in the specified root GameObject. This should be called when new UI elements are created (like menus) that weren't present when the font size was initially applied at startup.

    Declaration
    public void ApplyCurrentFontSizeToRoot(GameObject root)
    Parameters
    Type Name Description
    GameObject root

    The root GameObject to search for TMP_Text components.

    ApplyFontSizeFromSettings(IGameSettingsService)

    Applies the font size from the game settings service at startup. This method should be called after the UI service is initialized to ensure the saved font size is applied before any menus are shown.

    Declaration
    public void ApplyFontSizeFromSettings(IGameSettingsService gameSettingsService)
    Parameters
    Type Name Description
    IGameSettingsService gameSettingsService

    The game settings service to read the font size from.

    Remarks

    This is necessary because LoadPersistedGameSettings() dispatches OnGameSettingsOnValueUpdatedSignal before the UI service is installed and subscribed to the event. Without this explicit call, the font size would remain at the default value until the user opens the settings menu.

    GetFloatIncrement()

    Gets the configured increment step used when modifying float-type values in UI interactions.

    Declaration
    public float GetFloatIncrement()
    Returns
    Type Description
    float

    The float increment step value.

    GetFontSize()

    Gets the current font size setting.

    Declaration
    public float GetFontSize()
    Returns
    Type Description
    float

    The current font size as a float value.

    GetScale()

    Gets the current UI scale factor.

    Declaration
    public float GetScale()
    Returns
    Type Description
    float

    The current scale factor as a float, or 1.0f if UI root is null.

    GetTheme()

    Gets the current UI theme definition.

    Declaration
    public IUiThemeDefinition GetTheme()
    Returns
    Type Description
    IUiThemeDefinition

    The UI theme definition, or null if not initialized.

    GetThemeSounds()

    Gets the resolved theme sounds for the current UI theme.
    Maps theme sound definitions to audio player clips for UI interactions.

    Declaration
    public IUiThemeSounds GetThemeSounds()
    Returns
    Type Description
    IUiThemeSounds

    A configured UI theme sounds object with mapped audio clips, or null if theme is not initialized.

    HidePrimaryInputPrompt()

    Hides the primary input prompt view from the user.

    Declaration
    public void HidePrimaryInputPrompt()

    Initialize(IEventDispatcherService, IUiSettings, object, ILogService, IPrimaryInputPromptView)

    Initializes the UI service with all required dependencies and configurations.

    Declaration
    public void Initialize(IEventDispatcherService eventDispatcherService, IUiSettings uiSettings, object canvas, ILogService logService, IPrimaryInputPromptView primaryInputPromptView)
    Parameters
    Type Name Description
    IEventDispatcherService eventDispatcherService

    The event dispatcher service for UI event handling.

    IUiSettings uiSettings

    The UI settings configuration including themes and scaling.

    object canvas

    The Unity Canvas object to use for UI rendering.

    ILogService logService

    The logging service for debug and error messages.

    IPrimaryInputPromptView primaryInputPromptView

    The primary input prompt view for user interactions.

    InitializeEventDispatcher(IEventDispatcherService)

    Initializes the event dispatcher and subscribes to relevant UI events.

    Declaration
    public void InitializeEventDispatcher(IEventDispatcherService eventDispatcherService)
    Parameters
    Type Name Description
    IEventDispatcherService eventDispatcherService

    The event dispatcher service to use.

    InitializeService(IUiSettings, Canvas)

    Initializes the UI service with the specified settings and canvas.

    Declaration
    public void InitializeService(IUiSettings uiSettings, Canvas canvas)
    Parameters
    Type Name Description
    IUiSettings uiSettings

    The UI settings configuration to apply.

    Canvas canvas

    The Unity Canvas component to use for UI rendering.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when canvas or uiSettings is null.

    SetEventDispatcherService(IEventDispatcherService)

    Sets the event dispatcher service for UI event handling.

    Declaration
    public void SetEventDispatcherService(IEventDispatcherService eventDispatcherService)
    Parameters
    Type Name Description
    IEventDispatcherService eventDispatcherService

    The event dispatcher service instance.

    SetFontSize(SetFontSizeInput)

    Sets the font size for all text components in the UI.

    Declaration
    public void SetFontSize(SetFontSizeInput input)
    Parameters
    Type Name Description
    SetFontSizeInput input

    The input data containing the font size string to apply.

    Remarks

    After applying the new font size to all TMP_Text components, this method dispatches an OnFontSizeChangedSignal event. This event allows UI components (like menus) to trigger layout recalculation, similar to how locale changes trigger menu resizing.

    SetScale(UiSetScaleInput)

    Sets the UI scale for all views in the UI root.

    Declaration
    public void SetScale(UiSetScaleInput input)
    Parameters
    Type Name Description
    UiSetScaleInput input

    The input data containing the new scale value to apply.

    ShowPrimaryInputPrompt()

    Shows the primary input prompt view to the user.

    Declaration
    public void ShowPrimaryInputPrompt()

    SubscribeToEventDispatcherEvents()

    Subscribes to event dispatcher events related to UI settings and game settings changes.

    Declaration
    public void SubscribeToEventDispatcherEvents()

    Implements

    IUiService
    IService
    IFoundationSettings
    In this article
    © 2026 Serenity. All Rights Reserved