Skip to content

Game.Input.UIInputAction

Assembly: Assembly-CSharp
Namespace: Game.Input

Type: class

Base: UIBaseInputAction

Summary:
UIInputAction is a ScriptableObject representing a single UI-related input action. It wraps a Unity Input System InputActionReference and exposes it to the game's UI input framework. The asset provides metadata (processing mode, transform, device mask) and produces runtime IProxyAction state objects that forward events and value reads to an underlying ProxyAction from the global InputManager. It also supports providing a DisplayNameOverride for UI labeling of the action.


Fields

  • public InputActionReference m_Action
    Represents the Unity Input System action reference assigned to this UI input action. Used to look up the runtime ProxyAction via InputManager.instance.FindAction(m_Action.action).

  • public ProcessAs m_ProcessAs
    Specifies how the input should be processed (an enum used by the UI framework). Determines how the action's input values are interpreted/handled by UI logic.

  • public Transform m_Transform
    Optional transform reference used when constructing a DisplayNameOverride (for context-sensitive display names, e.g., localizing based on a transform).

  • public InputManager.DeviceType m_Mask = InputManager.DeviceType.All
    Device type mask restricting which input devices this UI action responds to. Default is All.

  • [NonSerialized] private UIInputActionPart[] m_ActionParts
    Cached, lazily-initialized array of UIInputActionPart used by the actionParts property. Marked NonSerialized because it is derived at runtime.

  • (Nested State) private readonly ProxyAction m_Action
    Backs the State.action property; the runtime ProxyAction retrieved from InputManager.

  • (Nested State) private readonly InputActivator m_Activator
    An InputActivator instance used to enable/disable and manage input activation for the specific source and device mask.

  • (Nested State) private readonly DisplayNameOverride m_DisplayName
    Optional DisplayNameOverride used to provide the localized/display name for the UI when this state is active.

Properties

  • public override IReadOnlyList<UIInputActionPart> actionParts { get; }
    Returns a read-only list of UIInputActionPart describing how this action is exposed to the UI. The list is lazily created on first access and contains a single element constructed from m_Action, m_ProcessAs, m_Transform, and m_Mask. The result is cached in m_ActionParts.

  • (Nested State) public ProxyAction action { get; }
    Exposes the underlying ProxyAction instance used by this State to read values and subscribe to interactions.

  • (Nested State) public DisplayNameOverride displayName { get; }
    Exposes the optional DisplayNameOverride used to provide the display name for the UI.

  • (Nested State) public IReadOnlyList<ProxyAction> actions { get; }
    Returns a read-only list containing the single ProxyAction this State wraps.

  • (Nested State) public bool enabled { get; set; }
    Enables or disables the InputActivator. Setting enabled will also set the DisplayNameOverride.active flag (if a display name exists) so the UI can show/hide the label appropriately.

  • (Nested State) bool IProxyAction.enabled { get; set; }
    Explicit interface implementation forwarding to the State.enabled property.

  • (Nested State) public event Action<ProxyAction, InputActionPhase> onInteraction
    Event that forwards add/remove directly to the underlying ProxyAction.onInteraction. Used to observe interaction phases (started/performed/canceled) for the action.

Constructors

  • public UIInputAction()
    Default ScriptableObject constructor — no special initialization in asset code. Runtime state objects are created via GetState methods.

  • (Nested State) internal State(string source, ProxyAction action, DisplayNameOverride displayName, InputManager.DeviceType mask)
    Creates a State wrapper for the given source identifier and ProxyAction. Initializes an InputActivator (with ignoreIsBuiltIn: true) to control activation for the given source and device mask, and stores the optional DisplayNameOverride. Throws ArgumentNullException if action is null.

Methods

  • public override IProxyAction GetState(string source)
    Creates and returns a new State instance for the given source. Uses InputManager.instance.FindAction(m_Action.action) to resolve the runtime ProxyAction and constructs a DisplayNameOverride with the asset's alias, display priority and transform. The returned State implements IProxyAction and IState and can be queried for input state and interactions.

  • public override IProxyAction GetState(string source, DisplayGetter displayNameGetter)
    Same as the single-argument GetState but uses the provided displayNameGetter delegate to obtain the DisplayNameOverride instead of constructing a default one. Allows callers to control how the display name is produced (for example, based on context or alternate localization sources).

  • (Nested State) public bool WasPressedThisFrame()
    Delegates to the wrapped ProxyAction.WasPressedThisFrame() to report whether the action was pressed in the current frame.

  • (Nested State) public bool WasReleasedThisFrame()
    Delegates to ProxyAction.WasReleasedThisFrame().

  • (Nested State) public bool IsPressed()
    Delegates to ProxyAction.IsPressed().

  • (Nested State) public bool IsInProgress()
    Delegates to ProxyAction.IsInProgress().

  • (Nested State) public float GetMagnitude()
    Delegates to ProxyAction.GetMagnitude() to retrieve the current input magnitude (useful for analog controls).

  • (Nested State) public T ReadValue<T>() where T : struct
    Generic value read forwarding to ProxyAction.ReadValue() for reading strongly-typed input values (Vector2, float, etc.).

  • (Nested State) public void Dispose()
    Disposes the InputActivator and DisplayNameOverride (if present). Should be invoked when the state is no longer needed to release resources and unregister activations.

Notes and behaviors: - GetState resolves the ProxyAction at runtime via InputManager.instance.FindAction; if m_Action is not set or the action name is not found, behavior depends on InputManager implementation (may return null or a placeholder). The State constructor will throw ArgumentNullException if the resolved ProxyAction is null. - The InputActivator is created with ignoreIsBuiltIn:true, meaning built-in inputs can be overridden/ignored per activation rules in the game input system. - DisplayNameOverride, when present, is updated by the State.enabled setter so that UI labels can reflect the active/inactive state automatically.

Usage Example

// Assume `uiInputAction` is a UIInputAction ScriptableObject reference in the inspector.

// Create a runtime proxy state for this action for a specific source (e.g., "MainMenu")
IProxyAction proxy = uiInputAction.GetState("MainMenu");

// Cast to the concrete State or IState if you need state-specific methods:
var state = proxy as Game.Input.UIInputAction.State;
if (state != null)
{
    // Subscribe to interaction events
    state.onInteraction += (proxyAction, phase) =>
    {
        // Handle started/performed/canceled phases
    };

    // Query input each frame
    if (state.WasPressedThisFrame())
    {
        // Perform action
    }

    // When done with the state:
    state.Dispose();
}