logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityModalController

    Unity-specific controller for handling modal dialog input and navigation.
    Manages user input processing for modal interactions including navigation, submit, and cancel actions.
    Integrates with the Unity Input System to provide keyboard and gamepad support for modal dialogs.

    Inheritance
    object
    UnityModalController
    Namespace: Serenity.Modal.Infrastructure.Controllers
    Assembly: Serenity.UnityModal.Infrastructure.dll
    Syntax
    public class UnityModalController : UnityUiController

    Constructors

    UnityModalController()

    Declaration
    public UnityModalController()

    Methods

    Cancel()

    Handles cancel input for the current modal dialog.
    Validates controller state and modal availability before executing cancel on the selected component.
    Throws exception if the controller is not properly initialized.

    Declaration
    public override void Cancel()
    Exceptions
    Type Condition
    Exception

    Thrown when the controller is not initialized.

    Initialize(string, string, float, int, float, IPlayerInputService, IPlayerInputActionBindingFactory<InputAction, CallbackContext>, IModalService, IComponent, object, ILogService)

    Initializes the modal controller with required services and configuration.
    Sets up player input handling, timing parameters, and modal service reference.
    Configures input action bindings and navigation timing behavior.

    Declaration
    public void Initialize(string id, string guid, float changeInterval, int consecutiveChangesBeforeSpeedUp, float fastChangeInterval, IPlayerInputService playerInputService, IPlayerInputActionBindingFactory<InputAction, InputAction.CallbackContext> playerInputActionBindingFactory, IModalService modalService, IComponent timer, object playerInput, ILogService logService)
    Parameters
    Type Name Description
    string id

    Unique identifier for the controller.

    string guid

    Globally unique identifier for the controller.

    float changeInterval

    Base interval between navigation changes.

    int consecutiveChangesBeforeSpeedUp

    Number of changes before speed increase.

    float fastChangeInterval

    Fast interval for repeated navigation.

    IPlayerInputService playerInputService

    Service for managing player input.

    IPlayerInputActionBindingFactory<InputAction, CallbackContext> playerInputActionBindingFactory

    Factory for creating input action bindings.

    IModalService modalService

    Modal service instance for modal operations.

    IComponent timer

    Timer component for navigation timing.

    object playerInput

    Unity PlayerInput instance.

    ILogService logService

    Service for logging operations.

    Navigate(Vector3)

    Handles navigation input for modal interactions.
    Processes vertical navigation for option selection and horizontal navigation for value changes.
    Restarts the hold direction timer to manage continuous input behavior.

    Declaration
    public override void Navigate(Vector3 direction)
    Parameters
    Type Name Description
    Vector3 direction

    The navigation direction vector (X for value changes, Y for option selection).

    ProcessNavigation(Vector3)

    Processes navigation input with modal-specific validation.
    Only processes navigation if a modal is currently active.
    Calls the base class navigation processing after validation.

    Declaration
    protected override void ProcessNavigation(Vector3 direction)
    Parameters
    Type Name Description
    Vector3 direction

    The navigation direction vector.

    Submit()

    Handles submit input for the current modal dialog.
    Validates controller state and modal availability before executing submit on the selected component.
    Throws exception if the controller is not properly initialized.

    Declaration
    public override void Submit()
    Exceptions
    Type Condition
    Exception

    Thrown when the controller is not initialized.

    UpdateSelectedOption(int)

    Updates the selected option in the current modal based on navigation direction.
    Navigates to next option for negative shift index, previous option for positive shift index.

    Declaration
    protected void UpdateSelectedOption(int shiftIndex)
    Parameters
    Type Name Description
    int shiftIndex

    The direction of option selection (negative for next, positive for previous).

    UpdateSelectedOptionValue(int)

    Updates the value of the currently selected option based on navigation direction.
    Increments value for positive shift index, decrements for negative shift index.

    Declaration
    protected void UpdateSelectedOptionValue(int shiftIndex)
    Parameters
    Type Name Description
    int shiftIndex

    The direction of value change (positive for increment, negative for decrement).

    In this article
    © 2026 Serenity. All Rights Reserved