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
UnityPlayerInputService
Assembly: Serenity.UnityPlayerInput.Infrastructure.dll
public class UnityPlayerInputService : MonoBehaviour, IPlayerInputService, IService, IFoundationSettings
Constructors
Declaration
public UnityPlayerInputService()
Fields
Declaration
protected float _changeInterval
Field Value
Declaration
protected int _consecutiveChangesBeforeSpeedUp
Field Value
_context
Declaration
protected TaskBuildContext _context
Field Value
Declaration
protected List<IController> _controllers
Field Value
Declaration
protected float _fastChangeInterval
Field Value
Declaration
Field Value
Declaration
Field Value
Declaration
protected IUiInputRouter _inputRouter
Field Value
Declaration
protected IPlayerInputJoinService _joinService
Field Value
Declaration
protected ILogService _logService
Field Value
Declaration
protected IReflectionCallTaskDefinition _onPrimaryJoinTask
Field Value
Declaration
protected PlayerInput _playerInput
Field Value
| Type |
Description |
| PlayerInput |
|
Declaration
protected IPrimaryDeviceSelector _primaryDeviceSelector
Field Value
Declaration
protected IPrimaryInputGate _primaryInputGate
Field Value
Declaration
protected IPlayerInputSlots _slots
Field Value
Declaration
protected string _uiActionMap
Field Value
Declaration
protected string _uiCancelAction
Field Value
Declaration
protected UnityUiInputRouter _uiInputRouter
Field Value
Declaration
protected string _uiNavigateAction
Field Value
Declaration
protected string _uiSubmitAction
Field Value
Declaration
protected string activeControllerId
Field Value
Properties
Gets or sets the ID of the currently active controller.
Declaration
public string ActiveControllerId { get; set; }
Property Value
Gets or sets the interval between input changes for navigation speed control.
Declaration
public float ChangeInterval { get; set; }
Property Value
Gets or sets the number of consecutive changes before switching to fast navigation mode.
Declaration
public int ConsecutiveChangesBeforeSpeedUp { get; set; }
Property Value
Gets or sets the fast change interval used after consecutive navigation changes.
Declaration
public float FastChangeInterval { get; set; }
Property Value
Gets or sets the globally unique identifier for this service instance.
Declaration
public string Guid { get; set; }
Property Value
Gets or sets the unique service identifier.
Declaration
public string Id { get; set; }
Property Value
Declaration
public IUiInputRouter InputRouter { get; set; }
Property Value
Declaration
public IPlayerInputJoinService JoinService { get; set; }
Property Value
Declaration
public ILogService LogService { get; set; }
Property Value
Gets or sets the task definition to execute when a primary device joins the input system.
Declaration
public IReflectionCallTaskDefinition OnPrimaryJoinTask { get; set; }
Property Value
Gets the Unity PlayerInput component managing input actions and devices.
Declaration
public PlayerInput PlayerInput { get; }
Property Value
| Type |
Description |
| PlayerInput |
|
Declaration
public IPrimaryDeviceSelector PrimaryDeviceSelector { get; set; }
Property Value
Declaration
public IPrimaryInputGate PrimaryInputGate { get; set; }
Property Value
Declaration
public IPlayerInputSlots Slots { get; set; }
Property Value
Gets or sets the name of the UI action map for navigation actions.
Declaration
public string UiActionMap { get; set; }
Property Value
Gets or sets the name of the UI cancel action for backing out of menus.
Declaration
public string UiCancelAction { get; set; }
Property Value
Gets the UI input router responsible for routing input to UI elements based on device selection.
Declaration
public UnityUiInputRouter UiInputRouter { get; }
Property Value
Gets or sets the name of the UI navigate action for menu navigation.
Declaration
public string UiNavigateAction { get; set; }
Property Value
Gets or sets the name of the UI submit action for confirming selections.
Declaration
public string UiSubmitAction { get; set; }
Property Value
Methods
Disables all registered controllers, clearing any active controller designation.
Useful for temporarily suspending all input handling or during state transitions.
Declaration
public void DisableAllControllers()
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()
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
Remarks
Exceptions
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.
|
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
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.
|
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
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
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