Class UnityBaseController
Abstract base class for Unity input controllers providing common functionality for input handling.
Manages PlayerInput integration, action binding registration, and controller lifecycle management.
Derived controllers must implement InitializeActions to define their specific input bindings.
Namespace: Serenity.InputGateway.Infrastructure.Controllers
Assembly: Serenity.UnityPlayerInput.Infrastructure.dll
Syntax
public abstract class UnityBaseController : MonoBehaviour, IController, IFoundationSettings
Constructors
UnityBaseController()
Declaration
protected UnityBaseController()
Fields
_foundationSettings
Declaration
protected IFoundationSettings _foundationSettings
Field Value
| Type | Description |
|---|---|
| IFoundationSettings | Foundation settings for this controller instance. |
_guid
Declaration
protected string _guid
Field Value
| Type | Description |
|---|---|
| string | Unique global identifier for this controller. |
_id
Declaration
protected string _id
Field Value
| Type | Description |
|---|---|
| string | Unique identifier for this controller instance. |
_isEnabled
Declaration
protected bool _isEnabled
Field Value
| Type | Description |
|---|---|
| bool | Flag indicating whether this controller is currently enabled. |
_isInitialized
Declaration
protected bool _isInitialized
Field Value
| Type | Description |
|---|---|
| bool | Flag indicating whether this controller has been initialized. |
_logService
Declaration
protected ILogService _logService
Field Value
| Type | Description |
|---|---|
| ILogService | Logging service for debug and error messages. |
_playerInput
Declaration
protected PlayerInput _playerInput
Field Value
| Type | Description |
|---|---|
| PlayerInput | PlayerInput component associated with this controller. |
_playerInputActionBindingFactory
Declaration
protected IPlayerInputActionBindingFactory<InputAction, InputAction.CallbackContext> _playerInputActionBindingFactory
Field Value
| Type | Description |
|---|---|
| IPlayerInputActionBindingFactory<InputAction, CallbackContext> |
_playerInputBindings
Declaration
protected List<IPlayerInputActionBinding<InputAction, InputAction.CallbackContext>> _playerInputBindings
Field Value
| Type | Description |
|---|---|
| List<IPlayerInputActionBinding<InputAction, InputAction.CallbackContext>> |
_playerInputService
Declaration
protected IPlayerInputService _playerInputService
Field Value
| Type | Description |
|---|---|
| IPlayerInputService | Service managing player input actions and bindings. |
Properties
Guid
Gets or sets the globally unique identifier for this controller.
Declaration
public string Guid { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The controller's globally unique identifier. |
Id
Gets or sets the unique controller identifier.
Declaration
public string Id { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The controller's unique identifier. |
IsInitialized
Gets a value indicating whether the controller has been properly initialized.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool | True if initialized; otherwise, false. |
Methods
Disable()
Disables the controller to stop processing input events.
Validates initialization state before disabling input handling.
Declaration
public void Disable()
Enable()
Enables the controller to start processing input events.
Validates initialization state before enabling input handling.
Declaration
public void Enable()
GetActionMap(string)
Retrieves the input action map by name from the PlayerInput component.
Searches through all available action maps to find a match by name.
Declaration
protected InputActionMap GetActionMap(string mapName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mapName | The name of the action map to retrieve. |
Returns
| Type | Description |
|---|---|
| InputActionMap | The InputActionMap with the specified name. |
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown when the specified action map is not found. |
Initialize(string, string, object, IPlayerInputService, IPlayerInputActionBindingFactory<InputAction, CallbackContext>, ILogService)
Initializes the controller with required dependencies and configures input action bindings.
Validates all input parameters, sets up PlayerInput integration, and registers the controller with the service.
Calls the abstract InitializeActions method for derived classes to configure their specific input handling.
Declaration
public virtual void Initialize(string id, string guid, object playerInput, IPlayerInputService playerInputService, IPlayerInputActionBindingFactory<InputAction, InputAction.CallbackContext> playerInputActionBindingFactory, ILogService logService)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | Unique identifier for this controller instance. |
| string | guid | Globally unique identifier for this controller. |
| object | playerInput | The Unity PlayerInput component to bind to. |
| IPlayerInputService | playerInputService | Service managing controller registration and lifecycle. |
| IPlayerInputActionBindingFactory<InputAction, CallbackContext> | playerInputActionBindingFactory | Factory for creating input action bindings. |
| ILogService | logService | Logging service for debug and error messages. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when playerInput is not a valid PlayerInput instance. |
| Exception | Thrown when PlayerInput actions are not initialized or empty. |
| ArgumentNullException | Thrown when required services are null. |
InitializeActions(string)
Abstract method that derived controllers must implement to configure their specific input action bindings.
Called during initialization to set up action map specific input handling.
Declaration
protected abstract void InitializeActions(string actionMapName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionMapName | The name of the action map to configure actions for. |
ValidateInitialized()
Validates that the controller has been properly initialized before performing operations.
Throws an exception if the controller is used before initialization.
Declaration
protected void ValidateInitialized()
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown when the controller is not initialized. |