logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class FoundationUiComponent

    Abstract base class for foundation UI components that bridge Unity GameObjects with the UI component system.
    Provides common functionality for UI component parameters, actions, audio integration, and view element management.

    Inheritance
    object
    FoundationUiComponent
    Implements
    IFoundationViewElement
    IUiComponent
    IComponent
    IFoundationSettings
    Namespace: Serenity.Ui.InterfaceAdapters.Views
    Assembly: Serenity.UnityUi.InterfaceAdapters.dll
    Syntax
    public abstract class FoundationUiComponent : MonoBehaviour, IFoundationViewElement, IUiComponent, IComponent, IFoundationSettings

    Constructors

    FoundationUiComponent()

    Declaration
    protected FoundationUiComponent()

    Fields

    Guid

    Declaration
    public string Guid
    Field Value
    Type Description
    string

    Foundation settings GUID.

    Id

    Declaration
    public string Id
    Field Value
    Type Description
    string

    Foundation settings identifier.

    _actions

    Declaration
    protected UiComponentActions _actions
    Field Value
    Type Description
    UiComponentActions

    Actions associated with the UI component.

    _audioClips

    Declaration
    protected Dictionary<string, AudioPlayerClip> _audioClips
    Field Value
    Type Description
    Dictionary<string, AudioPlayerClip>

    Audio clips associated with this UI component.

    _initialParameters

    Declaration
    protected UiComponentParameters _initialParameters
    Field Value
    Type Description
    UiComponentParameters

    Initial parameters for the UI component.

    _logService

    Declaration
    protected ILogService _logService
    Field Value
    Type Description
    ILogService

    Logging service for outputting log messages.

    _menuView

    Declaration
    protected IViewBase _menuView
    Field Value
    Type Description
    IViewBase

    Menu view associated with this UI component.

    _parameters

    Declaration
    protected UiComponentParameters _parameters
    Field Value
    Type Description
    UiComponentParameters

    Current parameters for the UI component.

    _uiCancelSfxKey

    Declaration
    protected string _uiCancelSfxKey
    Field Value
    Type Description
    string

    Sound effect key for cancel action.

    _uiChangeOptionValueSfxKey

    Declaration
    protected string _uiChangeOptionValueSfxKey
    Field Value
    Type Description
    string

    Sound effect key for changing option value.

    _uiErrorSfxKey

    Declaration
    protected string _uiErrorSfxKey
    Field Value
    Type Description
    string

    Sound effect key for error action.

    _uiHideSfxKey

    Declaration
    protected string _uiHideSfxKey
    Field Value
    Type Description
    string

    Sound effect key for hiding the UI element.

    _uiSelectOptionSfxKey

    Declaration
    protected string _uiSelectOptionSfxKey
    Field Value
    Type Description
    string

    Sound effect key for selecting an option.

    _uiShowSfxKey

    Declaration
    protected string _uiShowSfxKey
    Field Value
    Type Description
    string

    Sound effect key for showing the UI element.

    _uiSubmitSfxKey

    Declaration
    protected string _uiSubmitSfxKey
    Field Value
    Type Description
    string

    Sound effect key for submit action.

    _viewElement

    Declaration
    protected object _viewElement
    Field Value
    Type Description
    object

    View element associated with this UI component.

    Properties

    ComponentActions

    Declaration
    public IUiComponentActions ComponentActions { get; }
    Property Value
    Type Description
    IUiComponentActions

    ComponentParameters

    Declaration
    public IUiComponentParameters ComponentParameters { get; }
    Property Value
    Type Description
    IUiComponentParameters

    Methods

    Awake()

    Declaration
    public virtual void Awake()

    CanPlayAudio(string)

    Determines if audio can be played for the specified sound effect key.
    Checks if audio parameters and clips are properly configured and if the key exists in the audio clips dictionary.

    Declaration
    protected bool CanPlayAudio(string sfxKey)
    Parameters
    Type Name Description
    string sfxKey

    The sound effect key to check for audio playback capability

    Returns
    Type Description
    bool

    True if audio can be played for the specified key; otherwise, false

    GetGameObject()

    Gets the GameObject associated with this UI component's view element.
    Casts the view element to a GameObject and returns it.

    Declaration
    public GameObject GetGameObject()
    Returns
    Type Description
    GameObject

    GetId()

    Gets the ID associated with this UI component.

    Declaration
    public string GetId()
    Returns
    Type Description
    string

    The ID associated with this UI component.

    GetUiElement()

    Creates and returns the foundation view element associated with this UI component.
    Utilizes the foundation view element factory defined in the parameters to instantiate the element.

    Declaration
    public IFoundationViewElement GetUiElement()
    Returns
    Type Description
    IFoundationViewElement

    The created foundation view element.

    GetUiElementGameObject()

    Gets the GameObject associated with the UI element.

    Declaration
    public GameObject GetUiElementGameObject()
    Returns
    Type Description
    GameObject

    The GameObject representing the UI element.

    GetView()

    Gets the view associated with this UI component.

    Declaration
    public IViewBase GetView()
    Returns
    Type Description
    IViewBase

    The view associated with this UI component.

    GetViewElement()

    Gets the underlying view element associated with this UI component.
    Returns the internal reference to the view element object.

    Declaration
    public object GetViewElement()
    Returns
    Type Description
    object

    Initialize(IUiComponentParameters, IUiComponentActions, ILogService)

    Initializes the UI component with parameters, actions, and logging service.
    Sets up audio clips and ensures the foundation view element factory is assigned.
    Throws an exception if the factory is not provided.

    Declaration
    public virtual void Initialize(IUiComponentParameters parameters, IUiComponentActions uiComponentActions, ILogService logService)
    Parameters
    Type Name Description
    IUiComponentParameters parameters

    Parameters for configuring the UI component

    IUiComponentActions uiComponentActions

    Actions defining behavior for the UI component

    ILogService logService

    Logging service for outputting log messages

    Initialize(object)

    Initializes the view element with the provided object.
    Sets the internal reference to the view element.

    Declaration
    public void Initialize(object viewElement)
    Parameters
    Type Name Description
    object viewElement

    IsInitialized()

    Checks if the UI component has been properly initialized with parameters and a view element.
    Returns true if initialized; otherwise, false.

    Declaration
    public bool IsInitialized()
    Returns
    Type Description
    bool

    OnDestroy()

    Declaration
    public virtual void OnDestroy()

    OnDisable()

    Declaration
    public virtual void OnDisable()

    OnEnable()

    Declaration
    public virtual void OnEnable()

    ResetParameters()

    Resets the UI component parameters to their initial state.

    Declaration
    public virtual void ResetParameters()

    SetActive(bool)

    Sets the active state of the UI component's GameObject.
    Activates or deactivates the GameObject based on the provided boolean value.

    Declaration
    public void SetActive(bool active)
    Parameters
    Type Name Description
    bool active

    SetAudioClips()

    Sets up the audio clips dictionary based on the theme sounds defined in the parameters.
    Maps sound effect keys to their corresponding audio player clips for easy access during UI interactions.

    Declaration
    public void SetAudioClips()

    SetId(string)

    Sets the ID for this UI component.

    Declaration
    public void SetId(string id)
    Parameters
    Type Name Description
    string id

    The ID to set for this UI component.

    SetUiElement(IFoundationViewElement)

    Declaration
    public void SetUiElement(IFoundationViewElement uiElement)
    Parameters
    Type Name Description
    IFoundationViewElement uiElement

    SetUiElementGameObject(GameObject)

    Declaration
    public void SetUiElementGameObject(GameObject uiElementGameObject)
    Parameters
    Type Name Description
    GameObject uiElementGameObject

    SetView(IViewBase)

    Sets the view associated with this UI component.

    Declaration
    public void SetView(IViewBase view)
    Parameters
    Type Name Description
    IViewBase view

    The view to associate with this UI component.

    Update()

    Declaration
    public virtual void Update()

    UpdateUiElement<T>(Action<T>, IFoundationViewElement)

    Updates a specific Unity component on the UI element by executing the provided action.
    Utilizes the foundation view element factory to perform the update operation safely.

    Declaration
    protected abstract void UpdateUiElement<T>(Action<T> action, IFoundationViewElement element) where T : Component
    Parameters
    Type Name Description
    Action<T> action

    The action to execute on the component

    IFoundationViewElement element

    The foundation view element containing the component

    Type Parameters
    Name Description
    T

    The type of Unity component to update (must be a UnityEngine.Component)

    Implements

    IFoundationViewElement
    IUiComponent
    IComponent
    IFoundationSettings
    In this article
    © 2026 Serenity. All Rights Reserved