Game.Input.ProxyAction
Assembly:
Assembly-CSharp (likely)
Namespace:
Game.Input
Type:
class
Base:
IProxyAction
Summary:
Represents a mod-friendly wrapper around UnityEngine.InputSystem.InputAction used by the game's InputManager. ProxyAction aggregates per-device ProxyComposite data (bindings, composites), tracks activators, barriers, display name overrides, UI aliases and links to other actions. It exposes helpers to read action values (including raw reads that can temporarily disable processors), query state (pressed/in-progress/released), and manage action enablement and masks according to the game's input activation/blocking rules. The class also contains nested helper types for deferring bulk updates (DeferActionUpdatingWrapper, DeferActionStateUpdatingWrapper) and for representing link information between actions (LinkInfo). Use ProxyAction to inspect and interact with game actions from mods (subscribe to interactions, read values, create barriers/activators, etc.).
Fields
-
private static int counter
Tracks a global counter used to assign unique m_GlobalIndex values to ProxyAction instances. -
internal readonly int m_GlobalIndex
Unique index assigned to this ProxyAction; registered into InputManager.instance.actionIndex. -
private readonly InputAction m_SourceAction
The underlying Unity InputAction that this ProxyAction wraps. -
private readonly ProxyActionMap m_Map
Reference to the ProxyActionMap that owns this action. -
internal readonly HashSet<InputBarrier> m_Barriers
Active InputBarrier instances attached to this action. -
internal readonly HashSet<InputActivator> m_Activators
Active InputActivator instances attached to this action. -
internal readonly HashSet<DisplayNameOverride> m_DisplayOverrides
Display name override entries that can change the shown name for enabled actions. -
internal readonly HashSet<UIBaseInputAction> m_UIAliases
UI alias input actions that map to this action (used for UI input mappings). -
internal readonly HashSet<LinkInfo> m_LinkedActions
Set of LinkInfo describing other ProxyActions linked to this one (per-device links). -
private InputActivator m_DefaultActivator
Default activator created when shouldBeEnabled is set true for non-built-in actions. -
private InputActivator m_DefaultBuiltInActivator
Default built-in activator created/used to enable built-in actions. -
internal bool m_PreResolvedEnable
Computed flag indicating whether this action should be enabled based on pre-resolve logic. -
private InputManager.DeviceType m_AvailableMask
Mask of device types for which this action has composites available. -
private InputManager.DeviceType m_PreResolvedMask
Pre-resolved device mask after considering map enablement, activators and barriers. -
private InputManager.DeviceType m_Mask
Current applied device mask (changed via ApplyState). -
private bool m_IsSystemAction
Internal flag indicating whether the action is treated as a system action (special maps like Camera, Tool, etc). -
private readonly Dictionary<InputManager.DeviceType, ProxyComposite> m_Composites
Composites keyed by device type (one ProxyComposite per device type). -
private readonly List<ProxyBinding> m_Bindings
Flattened list of bindings collected from all composites (used for display and searches). -
private Action<ProxyAction, InputActionPhase> m_OnInteraction
Internal multicast used by the onInteraction event; when non-null, it hooks into the source action callbacks. -
internal static readonly DeferActionUpdatingWrapper sDeferUpdatingWrapper
Static helper to batch and defer Update() calls. -
internal static readonly DeferActionStateUpdatingWrapper sDeferStateUpdatingWrapper
Static helper to batch and defer UpdateState() calls.
Properties
-
public ProxyActionMap map { get; }
Reference to the ProxyActionMap that owns this action. -
internal InputAction sourceAction { get; }
The underlying Unity InputAction. Internal access. -
public IReadOnlyDictionary<InputManager.DeviceType, ProxyComposite> composites { get; }
Read-only view of per-device composites. -
public int compositesCount { get; }
Number of device composites available for this action. -
internal IReadOnlyCollection<InputBarrier> barriers { get; }
Active barriers collection (internal). -
internal IReadOnlyCollection<InputActivator> activators { get; }
Active activators collection (internal). -
public IEnumerable<ProxyBinding> bindings { get; }
Enumerates ProxyBinding items from all composites (flattened iterator). -
public bool isSet { get; }
True if any composite for this action has isSet == true (i.e., user binding exists). -
public bool isBuiltIn { get; }
True if any composite for this action is marked built-in. -
internal bool isDummy { get; }
True if this action has no composites or all composites are dummy; otherwise false. -
internal bool isSystemAction { get; }
Returns whether the action is treated as a system action (built-in and not overridden by UI aliases, or flagged). -
public InputManager.DeviceType availableDevices { get; }
Mask of devices that have composites (same as m_AvailableMask). -
public bool isKeyboardAction { get; }
True if Keyboard is among available devices. -
public bool isMouseAction { get; }
True if Mouse is among available devices. -
public bool isGamepadAction { get; }
True if Gamepad is among available devices. -
public bool isOnlyKeyboardAction { get; }
True if only Keyboard is available. -
public bool isOnlyMouseAction { get; }
True if only Mouse is available. -
public bool isOnlyGamepadAction { get; }
True if only Gamepad is available. -
public bool isMultiDeviceAction { get; }
True when this action has composites for more than one device. -
public string name { get; }
Name of the underlying input action (m_SourceAction.name). -
public string mapName { get; }
Name of the parent action map (m_Map.name). -
public string title { get; }
Combination mapName + "/" + name. -
public Type valueType { get; }
C# Type that best represents the action value (Vector2 for sticks/dpads/vector2, float for button/axis/default). -
bool IProxyAction.enabled { get; set; }
Explicit interface implementation — controls shouldBeEnabled (mod-facing enable flag for non-built-in actions). -
public bool enabled { get; internal set; }
Reflects whether the underlying InputAction is currently enabled. Setting will toggle a built-in activator when appropriate. -
public bool shouldBeEnabled { get; set; }
Determines whether the action should be enabled via a default InputActivator. Throws when attempting to directly set for built-in actions. -
internal bool preResolvedEnable { get; }
Pre-resolved enable flag calculated by UpdateState. -
public InputManager.DeviceType mask { get; }
The currently applied device mask for this action. -
internal InputManager.DeviceType preResolvedMask { get; }
Pre-resolved mask calculated in UpdateState before ApplyState is called. -
public DisplayNameOverride displayOverride { get; private set; }
Active display name override currently applied (null if none). -
public IEnumerable<string> usedKeys { get; }
Distinct bound paths (string) of all set bindings (useful for showing used key strings). -
public event Action<ProxyAction> onChanged
Raised when Update() completes and action metadata changed. -
public event Action<ProxyAction, InputActionPhase> onInteraction
Event raised when the underlying InputAction fires (started/performed/canceled). Subscribing will hook InputAction callbacks; unsubscribing removes them when no listeners remain.
Constructors
internal ProxyAction(ProxyActionMap map, InputAction sourceAction)
Creates a ProxyAction for the given map and InputAction. Registers the action into InputManager.instance.actionIndex and calls Update() to populate composites and bindings. Throws ArgumentNullException if map or sourceAction is null.
Methods
-
public unsafe T ReadValue<T>() where T : struct
Read the value of this action via the underlying InputAction's state. Returns default(T) if action state is missing. Uses actionStates and control index from InputActionState. -
public object ReadValueAsObject()
Wrapper calling m_SourceAction.ReadValueAsObject(). -
internal unsafe T ReadRawValue<T>(bool disableAll = true) where T : struct
Reads the raw binding value while optionally bypassing processors. If disableAll is true, temporarily sets the binding's processor count to 0; otherwise temporarily disables disableable processors. Useful when you need unprocessed raw inputs. -
public unsafe float GetMagnitude()
Returns the magnitude reported by the action's trigger state if available, otherwise 0f. -
public bool IsPressed()
Returns m_SourceAction.IsPressed(). -
public bool IsInProgress()
Returns m_SourceAction.IsInProgress(). -
public bool WasPressedThisFrame()
Returns m_SourceAction.WasPressedThisFrame(). -
public bool WasReleasedThisFrame()
Returns m_SourceAction.WasReleasedThisFrame(). -
public bool WasPerformedThisFrame()
Returns m_SourceAction.WasPerformedThisFrame(). -
private void SourceOnStarted(InputAction.CallbackContext context)
Internal bridge to raise onInteraction with InputActionPhase.Started. -
private void SourceOnPerformed(InputAction.CallbackContext context)
Internal bridge to raise onInteraction with InputActionPhase.Performed. -
private void SourceOnCanceled(InputAction.CallbackContext context)
Internal bridge to raise onInteraction with InputActionPhase.Canceled. -
internal void UpdateState(bool ignoreDefer = false)
Compute pre-resolved mask and enable state based on: whether the action map is enabled, active activators, barriers, and the action's available composites. If sDeferStateUpdatingWrapper is deferring, the update is queued. When the pre-resolved values change, InputManager.instance.OnPreResolvedActionChanged() is called. If action is a system action, ApplyState is invoked immediately. -
internal void ApplyState(bool newEnable, InputManager.DeviceType newMask)
Applies a new enable state and device mask to the underlying InputAction. If enable state changes, it will Enable()/Disable() the input action, call UpdateDisplay(), and notify InputManager.instance.OnEnabledActionsChanged(). If mask changes, InputManager.instance.OnActionMasksChanged() is triggered. -
internal void UpdateDisplay()
Selects the active displayOverride from m_DisplayOverrides if action is enabled and notifies InputManager.instance.OnActionDisplayNamesChanged(). -
internal void Update(bool ignoreDefer = false)
Rebuilds m_Composites and m_Bindings from InputManager.instance.GetComposites(sourceAction), repopulates linking of ProxyComposites to linked actions, updates internal flags such as m_AvailableMask and m_IsSystemAction, and notifies InputManager and subscribers via OnActionChanged/onChanged. If sDeferUpdatingWrapper is deferring, the update is queued. -
public bool TryGetComposite(InputManager.DeviceType device, out ProxyComposite composite)
Tries to obtain ProxyComposite for the given device type. -
public bool TryGetBinding(ProxyBinding sampleBinding, out ProxyBinding foundBinding)
Searches the composite for the sample binding's device and returns the found binding if present. -
public InputBarrier CreateBarrier(string barrierName = null, InputManager.DeviceType barrierMask = InputManager.DeviceType.All)
Creates and returns a new InputBarrier attached to this action. -
public InputActivator CreateActivator(string activatorName = null, InputManager.DeviceType activatorMask = InputManager.DeviceType.All)
Creates and returns a new InputActivator attached to this action (non-built-in). -
public bool ContainsComposite(InputManager.DeviceType device)
Returns true if action has a composite for the specified device (based on m_AvailableMask). -
internal static void LinkActions(LinkInfo action1, LinkInfo action2)
Links two LinkInfo entries together across both actions (convenience for the private overload). -
private static void LinkActions(LinkInfo link1, LinkInfo link2, bool addToOther)
Internal implementation for linking actions across devices. Ensures cross-linking and propagates existing linked sets. -
public override string ToString()
Returns a string representation like "Map/Action ( component: modifiers + path | ... )" constructed from the flatten bindings list. -
internal static DeferActionStateUpdatingWrapper DeferStateUpdating()
Acquire and return the static sDeferStateUpdatingWrapper to batch UpdateState calls. The returned IDisposable must be disposed to flush queued updates.
Usage Example
// Assuming you have access to InputManager and a ProxyAction:
ProxyAction proxy = /* get from InputManager or a ProxyActionMap */;
// Subscribe to interactions
proxy.onInteraction += (action, phase) =>
{
if (phase == InputActionPhase.Performed)
{
// Read current value in a type-safe way
if (action.valueType == typeof(float))
{
float v = action.ReadValue<float>();
Debug.Log($"Action {action.title} performed with value {v}");
}
else if (action.valueType == typeof(Vector2))
{
Vector2 v = action.ReadValue<Vector2>();
Debug.Log($"Action {action.title} performed with vector {v}");
}
}
};
// Create a temporary barrier that blocks gamepad for this action
InputBarrier barrier = proxy.CreateBarrier("Block Gamepad", InputManager.DeviceType.Gamepad);
barrier.blocked = true; // will change pre-resolved mask after UpdateState and ApplyState runs
// Create an activator to enable the action regardless of built-in settings
InputActivator activator = proxy.CreateActivator("Mod default", InputManager.DeviceType.All);
activator.enabled = true;
// Read raw value ignoring processors (useful for precise input handling)
Vector2 raw = proxy.ReadRawValue<Vector2>(disableAll: true);
// Defer many state updates to avoid repeated recalculations
using (ProxyAction.DeferStateUpdating())
{
// perform multiple changes to activators/barriers/etc.
// actual UpdateState calls are queued and flushed when disposed
}