Game.UI.InputActionBindings
Assembly:
Namespace: Game.UI
Type: public class
Base: CompositeBinding, IDisposable
Summary:
Manages UI input-action bindings for the game UI. InputActionBindings watches the game's InputManager UI action collection and control scheme, builds internal representations (ActionState) for UI actions, exposes event bindings ("input.onActionPerformed", "input.onActionReleased", "input.onActionsRefreshed") and a command ("input.setActionPriority"), and resolves conflicts between multiple UI actions bound to the same underlying input. It converts Input System interactions into the game's raw JSON event format and controls whether proxied input actions are activated based on priority, device mask and conflicts.
This class contains several nested helper types:
- ActionState — tracks the state, priority, transform and activation object for a single UI action part and can enable/disable its InputActivator and DisplayNameOverride.
- IEventTrigger and EventTrigger
Fields
-
private const int kDisabledPriority = -1
Used as the default "no consumer" priority for ActionState instances. -
private const string kGroup = "input"
Group name used when creating internal bindings. -
private RawEventBinding m_ActionPerformedBinding
Binding used to emit "input.onActionPerformed" events (writes input.InputActionEvent JSON). -
private RawEventBinding m_ActionReleasedBinding
Binding used to emit "input.onActionReleased" events for released/pass-through actions. -
private EventBinding m_ActionRefreshedBinding
Binding used to trigger "input.onActionsRefreshed" when the internal list of UI actions is refreshed. -
private readonly List<ActionState> m_UIActionStates = new List<ActionState>()
List of current ActionState objects (one per UI action part that has a proxy action). -
private readonly Dictionary<(ProxyAction, UIBaseInputAction.ProcessAs), IEventTrigger> m_Triggers = new Dictionary<(ProxyAction, UIBaseInputAction.ProcessAs), IEventTrigger>()
Lookup of event triggers keyed by (ProxyAction, ProcessAs). Each trigger subscribes to proxy action interactions and forwards them to all associated ActionState entries. -
private readonly Dictionary<string, int> m_ActionOrder = new Dictionary<string, int>()
Stores insertion start index for each UI action alias name inside m_UIActionStates to aid setting priority by action name. -
private bool m_ActionsDirty = true
Flag indicating that the action list must be refreshed (e.g., when InputManager actions change). -
private bool m_ConflictsDirty = true
Flag indicating that conflicts and priorities need to be re-evaluated (e.g., on control scheme change or action state change). -
private bool m_UpdateInProgress
Internal guard used to avoid marking dirty flags while an update is in progress.
Properties
- None (no public properties on the top-level class).
(The nested ActionState type exposes properties for name, action, mask, priority, state, transform, processAs, and isDisposed — see summary for usage.)
Constructors
public InputActionBindings()
Initializes the binding: it creates and adds the RawEventBinding and EventBinding entries (performed, released, setActionPriority, actionNames, onActionsRefreshed), populates the initial actionNames value from InputManager.instance.uiActionCollection, subscribes to InputManager.instance.EventActionsChanged and EventControlSchemeChanged, and marks its internal state to refresh actions/resolves conflicts on the next Update.
Methods
-
public void Dispose()
Unsubscribes from InputManager events, disposes all ActionState entries and all IEventTrigger instances, and clears the triggers dictionary. Should be called when this binding is no longer needed. -
public override bool Update()
Main update entry called by the binding system. If actions are dirty, RefreshActions() is called and onActionsRefreshed is triggered. If conflicts are dirty, ResolveConflicts() runs. Update uses m_UpdateInProgress to prevent recursive dirtying while updating. Returns the base CompositeBinding.Update() result. -
private void RefreshActions()
Rebuilds m_UIActionStates from the current InputManager.instance.uiActionCollection. Disposes previous ActionState objects, manages m_Triggers (removing triggers that no longer have states), creates new ActionState entries for every UI input action part that has a set ProxyAction, attaches each ActionState to a trigger (via IEventTrigger.GetTrigger), and populates m_ActionOrder for priority-setting. -
private void ResolveConflicts()
Sorts ActionState objects by priority and then: - Updates each ActionState state based on whether its ProxyAction is set, device masks match, and whether it has a priority assigned.
- Walks higher-to-lower priority order marking duplicates and conflicts (DisabledDuplicate or DisabledConflict).
-
Applies the resulting enabled/disabled states to InputActivator and DisplayNameOverride inside a ProxyAction.DeferStateUpdating() block so changes are applied coherently.
-
private void SetActionPriority(string action, int priority)
Handler for the "input.setActionPriority" binding. Looks up action start index from m_ActionOrder and updates the priority on each corresponding ActionState. -
private void SetConflictsDirty()
Marks conflicts as dirty unless an update is in progress. Used as a callback from ActionState.onChanged. -
private void OnActionsChanged()
Marks actions and conflicts dirty (called when InputManager.event actions change). -
private void OnControlSchemeChanged(Game.Input.InputManager.ControlScheme scheme)
Marks conflicts dirty (called when the input control scheme changes).
Usage Example
// Create and use the input action bindings within a UI binding context or manager:
var inputBindings = new Game.UI.InputActionBindings();
// Usually the binding system calls Update each frame. If manually updating:
inputBindings.Update();
// When done (e.g. UI shutdown), dispose:
inputBindings.Dispose();
Additional notes: - The class writes input events using RawEventBinding which emits JSON in the format the UI event system expects (type "input.InputActionEvent" with "action" and "value" properties). - The nested EventTrigger implementations handle type conversions (float <-> Vector2) and transforms (Positive/Negative/Left/Right/Horizontal/Vertical/etc.) so the same ProxyAction can be processed as a button, axis or vector2 depending on UI part settings. - ActionState controls activation via InputActivator (so the underlying ProxyAction will only be enabled when state == Enabled) and can override display names via DisplayNameOverride while enabled.