logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityModalService

    Unity-specific implementation of the modal service providing modal dialog functionality.
    Manages modal display, interaction handling, and lifecycle management within the Unity UI system.
    Handles event subscription for modal show/hide operations and integrates with the player input system.

    Inheritance
    object
    UnityModalService
    Implements
    IModalService
    IService
    IFoundationSettings
    Namespace: Serenity.Modal.Infrastructure.Services
    Assembly: Serenity.UnityModal.Infrastructure.dll
    Syntax
    public class UnityModalService : MonoBehaviour, IModalService, IService, IFoundationSettings

    Constructors

    UnityModalService()

    Declaration
    public UnityModalService()

    Fields

    _audioPlayerPlayClip

    Declaration
    protected AudioPlayerPlayClip _audioPlayerPlayClip
    Field Value
    Type Description
    AudioPlayerPlayClip

    Service for playing audio clips.

    _audioPlayerServiceId

    Declaration
    protected string _audioPlayerServiceId
    Field Value
    Type Description
    string

    Identifier for the audio player service used for UI sounds.

    _controllerId

    Declaration
    protected string _controllerId
    Field Value
    Type Description
    string

    Id of the controller to be used for player input.

    _currentModal

    Declaration
    protected IUiModal _currentModal
    Field Value
    Type Description
    IUiModal

    Reference to the currently displayed modal dialog, if any.

    _eventDispatcherService

    Declaration
    protected IEventDispatcherService _eventDispatcherService
    Field Value
    Type Description
    IEventDispatcherService

    Service for dispatching and subscribing to application events.

    _fontSize

    Declaration
    protected float _fontSize
    Field Value
    Type Description
    float

    Current font size used in the UI.

    _fontSizeKey

    Declaration
    protected string _fontSizeKey
    Field Value
    Type Description
    string

    Key for retrieving the font size setting.

    _foundationViewElementFactory

    Declaration
    protected IFoundationViewElementFactory _foundationViewElementFactory
    Field Value
    Type Description
    IFoundationViewElementFactory

    Factory for creating foundation view elements.

    _guid

    Declaration
    protected string _guid
    Field Value
    Type Description
    string

    The globally unique identifier for this modal service instance.

    _id

    Declaration
    protected string _id
    Field Value
    Type Description
    string

    The unique identifier for this modal service instance.

    _logService

    Declaration
    protected ILogService _logService
    Field Value
    Type Description
    ILogService

    Service for logging operations and errors.

    _maximumScaleValue

    Declaration
    protected float _maximumScaleValue
    Field Value
    Type Description
    float

    Maximum allowed UI scale value.

    _minimumScaleValue

    Declaration
    protected float _minimumScaleValue
    Field Value
    Type Description
    float

    Minimum allowed UI scale value.

    _modalButtonFactory

    Declaration
    protected IModalButtonFactory _modalButtonFactory
    Field Value
    Type Description
    IModalButtonFactory

    Factory for creating modal button components.

    _modalFactory

    Declaration
    protected UnityModalComponentFactory _modalFactory
    Field Value
    Type Description
    UnityModalComponentFactory

    Factory for creating modal components.

    _playerInputService

    Declaration
    protected IPlayerInputService _playerInputService
    Field Value
    Type Description
    IPlayerInputService

    Service for handling player input events.

    _scaleKey

    Declaration
    protected string _scaleKey
    Field Value
    Type Description
    string

    Key for retrieving the UI scale setting.

    _uiRoot

    Declaration
    protected GameObject _uiRoot
    Field Value
    Type Description
    GameObject

    Reference to the root GameObject of the UI canvas where modals will be displayed.

    _uiService

    Declaration
    protected IUiService _uiService
    Field Value
    Type Description
    IUiService

    Service for managing UI scaling and font size.

    _uiThemeDefinition

    Declaration
    protected IUiThemeDefinition _uiThemeDefinition
    Field Value
    Type Description
    IUiThemeDefinition

    UI theme definition for styling and audio configuration.

    Properties

    Guid

    Gets or sets the globally unique identifier for this modal service instance.

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

    The GUID string.

    Id

    Gets or sets the unique identifier for this modal 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

    GetCurrentModal()

    Gets the currently active modal dialog instance.
    Returns null if no modal is currently displayed.

    Declaration
    public IUiModal GetCurrentModal()
    Returns
    Type Description
    IUiModal

    The current modal instance, or null if no modal is active.

    InitializeEventDispatcher(IEventDispatcherService)

    Initializes the event dispatcher for modal-related events.
    Sets up event subscriptions for modal show and close operations.

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

    The event dispatcher service to initialize.

    InitializeService(object, IEventDispatcherService, IFoundationViewElementFactory, IModalButtonFactory, IUiComponentFactory, IUiThemeDefinition, IUiService, IPlayerInputService, AudioPlayerPlayClip, string, ILogService, string)

    Initializes the modal service with all required dependencies.
    Sets up canvas reference, factories, services, and event handling.
    Validates all required parameters and throws exceptions for null dependencies.

    Declaration
    public void InitializeService(object canvas, IEventDispatcherService eventDispatcherService, IFoundationViewElementFactory foundationViewElementFactory, IModalButtonFactory modalButtonFactory, IUiComponentFactory modalFactory, IUiThemeDefinition theme, IUiService uiService, IPlayerInputService playerInputService, AudioPlayerPlayClip audioPlayerPlayClip, string audioPlayerServiceId, ILogService logService, string controllerId)
    Parameters
    Type Name Description
    object canvas

    The Unity Canvas object for rendering modals.

    IEventDispatcherService eventDispatcherService

    Service for handling modal events.

    IFoundationViewElementFactory foundationViewElementFactory

    Factory for creating UI foundation elements.

    IModalButtonFactory modalButtonFactory

    Factory for creating modal button components.

    IUiComponentFactory modalFactory

    Factory for creating modal components.

    IUiThemeDefinition theme

    UI theme definition for styling.

    IUiService uiService

    Core UI service for font and scale management.

    IPlayerInputService playerInputService

    Service for managing player input controllers.

    AudioPlayerPlayClip audioPlayerPlayClip

    Audio playback functionality for UI sounds.

    string audioPlayerServiceId

    Identifier for the audio player service.

    ILogService logService

    Service for logging operations and errors.

    string controllerId

    Id of the controller to be used for player input.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when required dependencies are null.

    OnCloseModal()

    Coroutine that handles modal closure operations.
    Destroys the current modal and re-enables all player input controllers.

    Declaration
    protected IEnumerator OnCloseModal()
    Returns
    Type Description
    IEnumerator

    An IEnumerator for coroutine execution.

    OnCloseModal(EventDispatcherSignal)

    Handles the OnCloseModalSignal event signal.
    Initiates the modal closing process by starting the destruction coroutine.

    Declaration
    protected void OnCloseModal(EventDispatcherSignal signal)
    Parameters
    Type Name Description
    EventDispatcherSignal signal

    The event signal triggering modal closure.

    OnShowModal(EventDispatcherSignal)

    Handles the OnShowModalSignal event signal.
    Extracts modal data from the signal and displays the modal while setting the active controller.

    Declaration
    protected void OnShowModal(EventDispatcherSignal signal)
    Parameters
    Type Name Description
    EventDispatcherSignal signal

    The event signal containing modal display data.

    SetEventDispatcherService(IEventDispatcherService)

    Sets the event dispatcher service for handling modal-related events.

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

    The event dispatcher service to set.

    ShowModal(OnShowModalInput)

    Displays a modal dialog based on the provided input data.
    Creates modal buttons, configures parameters, and instantiates the modal UI component.
    Validates required services and factories before proceeding with modal creation.

    Declaration
    public void ShowModal(OnShowModalInput input)
    Parameters
    Type Name Description
    OnShowModalInput input

    The input data containing modal configuration and button information.

    SubscribeToEventDispatcherEvents()

    Subscribes to event dispatcher events for modal operations.
    Registers handlers for OnShowModalSignal and OnCloseModalSignal events.

    Declaration
    public void SubscribeToEventDispatcherEvents()

    Implements

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