logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityPlayerInputService

    Unity implementation of the player input service managing input handling, controller registration, and action map switching.
    Provides centralized control over Unity's Input System with support for multiple controllers and UI input routing.
    Handles primary device join notifications and executes associated tasks for player input lifecycle management.

    Inheritance
    object
    UnityPlayerInputService
    Implements
    IPlayerInputService
    IService
    IFoundationSettings
    Namespace: Serenity.InputGateway.Infrastructure.Services
    Assembly: Serenity.UnityPlayerInput.Infrastructure.dll
    Syntax
    public class UnityPlayerInputService : MonoBehaviour, IPlayerInputService, IService, IFoundationSettings

    Constructors

    UnityPlayerInputService()

    Declaration
    public UnityPlayerInputService()

    Fields

    _changeInterval

    Declaration
    protected float _changeInterval
    Field Value
    Type Description
    float

    _consecutiveChangesBeforeSpeedUp

    Declaration
    protected int _consecutiveChangesBeforeSpeedUp
    Field Value
    Type Description
    int

    _context

    Declaration
    protected TaskBuildContext _context
    Field Value
    Type Description
    TaskBuildContext

    _controllers

    Declaration
    protected List<IController> _controllers
    Field Value
    Type Description
    List<IController>

    _fastChangeInterval

    Declaration
    protected float _fastChangeInterval
    Field Value
    Type Description
    float

    _guid

    Declaration
    protected string _guid
    Field Value
    Type Description
    string

    _id

    Declaration
    protected string _id
    Field Value
    Type Description
    string

    _inputRouter

    Declaration
    protected IUiInputRouter _inputRouter
    Field Value
    Type Description
    IUiInputRouter

    _joinService

    Declaration
    protected IPlayerInputJoinService _joinService
    Field Value
    Type Description
    IPlayerInputJoinService

    _logService

    Declaration
    protected ILogService _logService
    Field Value
    Type Description
    ILogService

    _onPrimaryJoinTask

    Declaration
    protected IReflectionCallTaskDefinition _onPrimaryJoinTask
    Field Value
    Type Description
    IReflectionCallTaskDefinition

    _playerInput

    Declaration
    protected PlayerInput _playerInput
    Field Value
    Type Description
    PlayerInput

    _primaryDeviceSelector

    Declaration
    protected IPrimaryDeviceSelector _primaryDeviceSelector
    Field Value
    Type Description
    IPrimaryDeviceSelector

    _primaryInputGate

    Declaration
    protected IPrimaryInputGate _primaryInputGate
    Field Value
    Type Description
    IPrimaryInputGate

    _slots

    Declaration
    protected IPlayerInputSlots _slots
    Field Value
    Type Description
    IPlayerInputSlots

    _uiActionMap

    Declaration
    protected string _uiActionMap
    Field Value
    Type Description
    string

    _uiCancelAction

    Declaration
    protected string _uiCancelAction
    Field Value
    Type Description
    string

    _uiInputRouter

    Declaration
    protected UnityUiInputRouter _uiInputRouter
    Field Value
    Type Description
    UnityUiInputRouter

    _uiNavigateAction

    Declaration
    protected string _uiNavigateAction
    Field Value
    Type Description
    string

    _uiSubmitAction

    Declaration
    protected string _uiSubmitAction
    Field Value
    Type Description
    string

    activeControllerId

    Declaration
    protected string activeControllerId
    Field Value
    Type Description
    string

    Properties

    ActiveControllerId

    Gets or sets the ID of the currently active controller.

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

    ChangeInterval

    Gets or sets the interval between input changes for navigation speed control.

    Declaration
    public float ChangeInterval { get; set; }
    Property Value
    Type Description
    float

    ConsecutiveChangesBeforeSpeedUp

    Gets or sets the number of consecutive changes before switching to fast navigation mode.

    Declaration
    public int ConsecutiveChangesBeforeSpeedUp { get; set; }
    Property Value
    Type Description
    int

    FastChangeInterval

    Gets or sets the fast change interval used after consecutive navigation changes.

    Declaration
    public float FastChangeInterval { get; set; }
    Property Value
    Type Description
    float

    Guid

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

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

    Id

    Gets or sets the unique service identifier.

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

    InputRouter

    Declaration
    public IUiInputRouter InputRouter { get; set; }
    Property Value
    Type Description
    IUiInputRouter

    JoinService

    Declaration
    public IPlayerInputJoinService JoinService { get; set; }
    Property Value
    Type Description
    IPlayerInputJoinService

    LogService

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

    OnPrimaryJoinTask

    Gets or sets the task definition to execute when a primary device joins the input system.

    Declaration
    public IReflectionCallTaskDefinition OnPrimaryJoinTask { get; set; }
    Property Value
    Type Description
    IReflectionCallTaskDefinition

    PlayerInput

    Gets the Unity PlayerInput component managing input actions and devices.

    Declaration
    public PlayerInput PlayerInput { get; }
    Property Value
    Type Description
    PlayerInput

    PrimaryDeviceSelector

    Declaration
    public IPrimaryDeviceSelector PrimaryDeviceSelector { get; set; }
    Property Value
    Type Description
    IPrimaryDeviceSelector

    PrimaryInputGate

    Declaration
    public IPrimaryInputGate PrimaryInputGate { get; set; }
    Property Value
    Type Description
    IPrimaryInputGate

    Slots

    Declaration
    public IPlayerInputSlots Slots { get; set; }
    Property Value
    Type Description
    IPlayerInputSlots

    UiActionMap

    Gets or sets the name of the UI action map for navigation actions.

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

    UiCancelAction

    Gets or sets the name of the UI cancel action for backing out of menus.

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

    UiInputRouter

    Gets the UI input router responsible for routing input to UI elements based on device selection.

    Declaration
    public UnityUiInputRouter UiInputRouter { get; }
    Property Value
    Type Description
    UnityUiInputRouter

    UiNavigateAction

    Gets or sets the name of the UI navigate action for menu navigation.

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

    UiSubmitAction

    Gets or sets the name of the UI submit action for confirming selections.

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

    Methods

    DisableAllControllers()

    Disables all registered controllers, clearing any active controller designation.
    Useful for temporarily suspending all input handling or during state transitions.

    Declaration
    public void DisableAllControllers()

    EnableAllControllers()

    Enables all registered controllers simultaneously, clearing any active controller designation.
    Useful for scenarios where multiple controllers need to be active at the same time.

    Declaration
    public void EnableAllControllers()

    GetPlayerInput()

    Returns the underlying Unity PlayerInput component for advanced input system operations.
    Provides access to the raw PlayerInput object for cases requiring direct Unity Input System integration.

    Declaration
    public object GetPlayerInput()
    Returns
    Type Description
    object

    The PlayerInput component instance as an object.

    InitializeService(object, IPlayerInputServiceSettingsDefinition, TaskBuildContext, IUiInputRouter, IPlayerInputSlots, IUiInputRouter, IPrimaryDeviceSelector, IPrimaryInputGate, IPlayerInputJoinService)

    Initializes the player input service with required components and configuration settings.
    Sets up PlayerInput component, UI input routing, action map configuration, and task execution context.
    Configures navigation timing parameters and primary join event handling.

    Declaration
    public void InitializeService(object playerInput, IPlayerInputServiceSettingsDefinition settings, TaskBuildContext context, IUiInputRouter uiInputRouter, IPlayerInputSlots slots, IUiInputRouter inputRouter, IPrimaryDeviceSelector primaryDeviceSelector, IPrimaryInputGate primaryInputGate, IPlayerInputJoinService joinService)
    Parameters
    Type Name Description
    object playerInput

    The Unity PlayerInput component instance to manage.

    IPlayerInputServiceSettingsDefinition settings

    Configuration settings defining UI actions, timing, and behavior.

    TaskBuildContext context

    Task build context for executing reflection-based tasks.

    IUiInputRouter uiInputRouter

    UI input router for directing input to appropriate UI elements.

    IPlayerInputSlots slots

    The player input slots to manage.

    IUiInputRouter inputRouter

    The input router to handle input routing.

    IPrimaryDeviceSelector primaryDeviceSelector

    The primary device selector to handle primary device selection.

    IPrimaryInputGate primaryInputGate

    The primary input gate to handle primary input gating.

    IPlayerInputJoinService joinService

    The player input join service to handle player joining.

    Remarks

    This method performs comprehensive validation of input parameters to ensure robustness and reliability.

    Exceptions
    Type Condition
    ArgumentException

    Thrown when playerInput is not a valid PlayerInput instance.

    ArgumentNullException

    Thrown when any required parameter is null.

    Exception

    Thrown when any other error occurs during initialization.

    NotifyPrimaryJoined(PrimaryJoinInfo)

    Handles notification when a primary input device joins the system.
    Logs device information, routes UI input, executes the primary join task, and caches join information.
    This method is called when a player becomes the primary input device for UI navigation.

    Declaration
    public void NotifyPrimaryJoined(PrimaryJoinInfo info)
    Parameters
    Type Name Description
    PrimaryJoinInfo info

    Information about the primary device that joined including device ID, display name, control scheme, and user index.

    RegisterController(IController)

    Registers a controller with the input service for input event handling.
    Prevents duplicate registrations and maintains a collection of active controllers for management.

    Declaration
    public void RegisterController(IController controller)
    Parameters
    Type Name Description
    IController controller

    The controller to register for input handling.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when controller is null.

    SetActionMap(string)

    Switches the active action map for the PlayerInput component.
    Validates that the specified action map exists before attempting to switch to prevent runtime errors.

    Declaration
    public void SetActionMap(string actionMapName)
    Parameters
    Type Name Description
    string actionMapName

    The name of the action map to activate.

    Exceptions
    Type Condition
    Exception

    Thrown when the specified action map does not exist.

    SetActiveController(string)

    Sets the specified controller as the active controller and disables all others.
    Enables only the controller matching the provided ID while disabling all other registered controllers.

    Declaration
    public void SetActiveController(string controllerId)
    Parameters
    Type Name Description
    string controllerId

    The unique identifier of the controller to activate.

    Exceptions
    Type Condition
    ArgumentException

    Thrown when controllerId is null or empty.

    UnregisterController(IController)

    Unregisters a controller from the input service to stop receiving input events.
    Safely removes the controller from the active collection if it was previously registered.

    Declaration
    public void UnregisterController(IController controller)
    Parameters
    Type Name Description
    IController controller

    The controller to unregister from input handling.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when controller is null.

    UnsetActiveController()

    Clears the active controller designation and disables all registered controllers.
    Similar to DisableAllControllers but specifically clears the active controller ID.

    Declaration
    public void UnsetActiveController()

    Implements

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