logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityModalComponent

    Unity implementation of a modal dialog UI component.
    Provides modal display functionality with title, text content, and interactive buttons.
    Handles animation states, user interaction, and button navigation within modal dialogs.

    Inheritance
    object
    UnityModalComponent
    Implements
    IUiModal
    IComponent
    IFoundationSettings
    Namespace: Serenity.Modal.Infrastructure.Views
    Assembly: Serenity.UnityModal.Infrastructure.dll
    Syntax
    public class UnityModalComponent : UnityUiComponent, IUiModal, IComponent, IFoundationSettings

    Constructors

    UnityModalComponent()

    Declaration
    public UnityModalComponent()

    Fields

    _hideAnimationState

    Declaration
    protected string _hideAnimationState
    Field Value
    Type Description
    string

    Animation state name used to detect when the hide animation is playing.

    _showAnimationState

    Declaration
    protected string _showAnimationState
    Field Value
    Type Description
    string

    Animation state name used to detect when the show animation is playing.

    _showToggleParameter

    Declaration
    protected string _showToggleParameter
    Field Value
    Type Description
    string

    Animator bool parameter name used to toggle showing/hiding the modal.

    Properties

    ModalParameters

    Gets or sets the modal parameters containing configuration and content data.

    Declaration
    public IUiModalParameters ModalParameters { get; set; }
    Property Value
    Type Description
    IUiModalParameters

    The current modal parameters instance.

    Methods

    DestroyModal()

    Destroys the modal with proper animation handling.
    Plays the hide animation if an animator is present, then destroys the GameObject.
    Falls back to immediate destruction if no animator is available.

    Declaration
    public IEnumerator DestroyModal()
    Returns
    Type Description
    IEnumerator

    An IEnumerator for coroutine execution.

    ExecuteChangeOptionValue(UiOptionValue)

    Executes a value change operation on the currently selected option.
    Sets the selected option's value based on the provided option value.

    Declaration
    public void ExecuteChangeOptionValue(UiOptionValue optionValue)
    Parameters
    Type Name Description
    UiOptionValue optionValue

    The option value to set.

    ExecuteSelectOption()

    Executes the submit action on the currently selected option.
    Logs a warning if no option is selected for execution.

    Declaration
    public void ExecuteSelectOption()

    GetOptionByIndex(int)

    Gets an interactive button component by its index.
    Validates the index range and returns the corresponding button.

    Declaration
    public IUiInteractable GetOptionByIndex(int index)
    Parameters
    Type Name Description
    int index

    The zero-based index of the button to retrieve.

    Returns
    Type Description
    IUiInteractable

    The interactive button component at the specified index.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    Thrown when the index is out of valid range.

    GetSelectedOption()

    Gets the currently selected interactive button component.
    Returns null if no buttons are available or the selected index is invalid.

    Declaration
    public IUiInteractable GetSelectedOption()
    Returns
    Type Description
    IUiInteractable

    The currently selected button component, or null if none is selected.

    GetSelectedOptionIndex()

    Gets the index of the currently selected button option.

    Declaration
    public int GetSelectedOptionIndex()
    Returns
    Type Description
    int

    The zero-based index of the selected button.

    Initialize(IUiComponentParameters, IUiComponentActions, ILogService)

    Initializes the modal component with provided parameters and actions.
    Sets up modal content including title, text, buttons, and font sizes.
    Validates modal parameters and starts the show animation if an animator is present.

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

    Modal configuration parameters.

    IUiComponentActions uiComponentActions

    UI component actions for interaction handling.

    ILogService logService

    Service for logging operations.

    Exceptions
    Type Condition
    Exception

    Thrown when modal parameters are null.

    OnDestroy()

    Handles cleanup operations when the modal component is destroyed.
    Calls the base class OnDestroy implementation.

    Declaration
    public override void OnDestroy()

    OnDraggingEnd()

    Ends dragging interaction on the currently selected option.
    Logs a warning if no option is selected for ending drag.

    Declaration
    public void OnDraggingEnd()

    OnDraggingStart()

    Initiates dragging interaction on the currently selected option.
    Logs a warning if no option is selected for dragging.

    Declaration
    public void OnDraggingStart()

    SelectNextOption()

    Selects the next button option in the modal.
    Cycles through buttons with wraparound and updates focus states.

    Declaration
    public void SelectNextOption()

    SelectPreviousOption()

    Selects the previous button option in the modal.
    Cycles through buttons with wraparound and updates focus states.

    Declaration
    public void SelectPreviousOption()

    SetButtons(List<IUiInteractable>)

    Sets the interactive buttons for the modal dialog.
    Clears existing buttons and adds new ones to the buttons wrapper.
    Handles layout updates and sets initial button focus.

    Declaration
    public void SetButtons(List<IUiInteractable> buttons)
    Parameters
    Type Name Description
    List<IUiInteractable> buttons

    The list of interactive button components to add.

    SetNextOptionValue()

    Increments the value of the currently selected option.
    Logs a warning if the selected option is not an interactive component.

    Declaration
    public void SetNextOptionValue()

    SetPreviousOptionValue()

    Decrements the value of the currently selected option.
    Logs a warning if the selected option is not an interactive component.

    Declaration
    public void SetPreviousOptionValue()

    SetText(string)

    Declaration
    public void SetText(string text)
    Parameters
    Type Name Description
    string text

    The body text to display.

    SetTextFontSize(float)

    Sets the font size for the modal body text.

    Declaration
    public void SetTextFontSize(float fontSize)
    Parameters
    Type Name Description
    float fontSize

    The font size value to apply.

    SetTitle(string)

    Declaration
    public void SetTitle(string title)
    Parameters
    Type Name Description
    string title

    The title text to display.

    SetTitleFontSize(float)

    Sets the font size for the modal title text.

    Declaration
    public void SetTitleFontSize(float fontSize)
    Parameters
    Type Name Description
    float fontSize

    The font size value to apply.

    Implements

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