Game.Input.ProxyBinding
Assembly: Assembly-CSharp.dll
Namespace: Game.Input
Type: struct
Base: System.ValueType
Summary:
Represents a serializable "proxy" for an input binding (a binding entry inside a composite or action definition). ProxyBinding stores map/action/name identifiers, device/group, control path and modifiers, and keeps references to its source CompositeInstance and UI alias. It provides helpers for comparing bindings (including multiple comparer variants), detecting conflicts against other bindings in the InputManager, producing human readable control paths, cloning/copying, and JSON writing for tools/UI. The struct also exposes nested helper types:
- Comparer: flexible equality comparer with options to compare by map/action/name/path/modifiers/usages/device/component.
- ModifiersListComparer: comparer specialized for lists of ProxyModifier (ignores order).
- Watcher: watches a binding's underlying action for changes and updates the proxy binding accordingly.
- ConflictType: enum describing conflict classification with built-in or non-built-in bindings.
Fields
-
private string m_MapName
Stores the input action map name (e.g., "Gameplay"). -
private string m_ActionName
Stores the action name within the map (e.g., "MoveCamera"). -
private ActionComponent m_Component
Component information identifying which action/component this binding belongs to. -
private string m_Name
Logical name of this binding inside the composite (e.g., "up", "down", or a part name). -
private InputManager.DeviceType m_Device
Device mask (keyboard, mouse, gamepad, etc.). Used to filter conflicts and to display device. -
private string m_Path
The control path (control binding) for this proxy (e.g., "/w" or " /leftButton"). -
private ProxyModifier[] m_Modifiers
Array of modifiers (other control paths used as modifiers for this binding). -
private string m_OriginalPath
Optional original path used to track whether a binding has been changed from its original. -
private ProxyModifier[] m_OriginalModifiers
Optional original modifiers array for change tracking. -
private CompositeInstance m_Source
Reference to the CompositeInstance that created or owns this proxy binding (used to retrieve source metadata like isRebindable, builtIn, etc). -
private UIBaseInputAction m_Alies
Optional alias/overlay UI action providing alternate display/title/option group information. -
private int m_HasConflictVersion
Versioning field used to cache hasConflicts result until InputManager.actionVersion changes. -
private ConflictType m_HasConflicts
Cached conflict result (enum bitmask). -
private int m_ConflictVersion
Versioning field used to cache conflicts list until InputManager.actionVersion changes. -
private IList<ProxyBinding> m_Conflicts
Cached list of conflicting bindings.
Properties
-
public static Comparer defaultComparer => Comparer.defaultComparer
Default comparer instance used for full equality (map, action, name, device). -
public static ModifiersListComparer defaultModifiersComparer => ModifiersListComparer.defaultComparer
Default comparer for modifier lists (order-insensitive). -
public string mapName => m_MapName
Action map name (read-only). -
public string actionName => m_ActionName
Action name within the map (read-only). -
public ActionComponent component => m_Component
Action component identifier (read-only). -
public string name => m_Name
Logical binding name (read-only). -
internal ProxyAction action => InputManager.instance.FindAction(m_MapName, m_ActionName)
Resolve the ProxyAction from the InputManager for this proxy (internal). -
public bool isBuiltIn
True if the source CompositeInstance indicates this binding is built-in. -
public bool isRebindable
True if the source CompositeInstance allows rebinds. -
public bool isModifiersRebindable
True if modifiers are rebindable on the source. -
public bool allowModifiers
True if the source allows modifiers. -
public bool canBeEmpty
True if the source binding is allowed to be empty. -
public bool developerOnly
True if the source binding is developer-only. -
internal bool isDummy
True if the source composite is flagged as dummy (internal use). -
internal bool isHidden
True if the binding should be hidden from options (consults alias or source). -
internal OptionGroupOverride optionGroupOverride
Option group override for grouping in UI (computed from source and alias). -
public Usages usages => m_Source?.usages ?? Usages.empty
Usages mask describing contexts where this binding applies. -
public ProxyBinding original
Returns a copy representing the original (unmodified) binding: if original values exist they replace current path/modifiers. -
public bool isOriginal
True if the current path/modifiers equal the original stored ones. -
public ConflictType hasConflicts
Checks (and caches) whether this binding conflicts with other bindings in the InputManager. Returns a ConflictType bitmask indicating built-in/non-built-in conflicts. -
public IList<ProxyBinding> conflicts
Returns (and caches) the list of ProxyBinding instances that conflict with this binding. -
public string path { get; set; }
Getter/setter for the m_Path. Setter resets conflict cache. -
public IReadOnlyList<ProxyModifier> modifiers { get; set; }
Get or set modifiers. Setting will normalize (distinct + sorted) and resets conflict cache. -
public string originalPath { get; set; }
Original path storage (setter resets conflict cache). -
public IReadOnlyList<ProxyModifier> originalModifiers { get; set; }
Original modifiers (setter resets conflict cache). -
public string group
(Obsolete)
String representation of device (kept for compatibility; maps to device property). -
public InputManager.DeviceType device { get; set; }
Device mask (getter/setter). -
public bool isKeyboard
True if device includes keyboard. -
public bool isMouse
True if device includes mouse. -
public bool isGamepad
True if device includes gamepad. -
public bool isSet
True when path is not null or empty. -
internal UIBaseInputAction alies { get; set; }
Internal get/set for the alias action instance. -
internal bool isAlias
True when an alias instance is present. -
public string title
Readable title derived from map/action/name or alias + name.
Constructors
-
public ProxyBinding(string mapName, string actionName, ActionComponent component, string name, CompositeInstance source)
Create a new ProxyBinding with explicit identifiers and source. Initializes device to None and path/modifiers to empty. -
public ProxyBinding(InputAction action, ActionComponent component, string name, CompositeInstance source)
Convenience constructor using a Unity InputAction instance (extracts action.actionMap.name and action.name).
Methods
-
public ProxyBinding Copy()
Creates a shallow copy of the ProxyBinding including cached conflict metadata and arrays (conflicts are copied to a new array if non-empty). Useful when you need an independent snapshot. -
public static bool ConflictsWith(ProxyBinding x, ProxyBinding y, bool checkUsage)
Determines whether two ProxyBinding instances conflict. Checks path set, device equality, path/modifiers equality (uses either pathAndModifiersComparer or onlyPathComparer depending on allowModifiers), and optionally tests usages compatibility. -
public IEnumerable<string> ToHumanReadablePath()
Yield human readable control paths for each modifier followed by the binding path (uses ControlPath.ToHumanReadablePath). Helpful for UI display. -
public ProxyBinding WithPath(string newPath)
Fluent setter for path (sets property, resets caches and returns this). -
public ProxyBinding WithModifiers(IReadOnlyList<ProxyModifier> newModifiers)
Fluent setter for modifiers (normalizes and returns this). -
internal Watcher CreateWatcher(Action<ProxyBinding> onChange = null)
Creates a Watcher bound to this ProxyBinding which listens to action changes and updates the proxy binding instance if the underlying action bindings change. Use Dispose() on returned Watcher. -
private void SetModifiers(out ProxyModifier[] field, IReadOnlyList<ProxyModifier> value)
Normalizes the incoming modifiers list: empty -> empty array; single -> ToArray; multiple -> distinct-by-path and sorted using ProxyModifier.pathComparer. -
public void ResetConflictCache()
Invalidate cached conflict/version fields so subsequent hasConflicts/conflicts queries refresh against InputManager. -
internal string GetOptionsGroup()
Returns the option group string used for UI grouping. If an OptionGroupOverride is set it will try to use the DescriptionAttribute of the enum field, otherwise falls back to mapName. -
public override string ToString()
Debug-friendly string describing the binding: "map/action/name - [binding or Not set] (usages)". Shows modifiers + path when set. -
public void Write(IJsonWriter writer)
Serialize important binding metadata to the provided IJsonWriter (type, binding path, modifier control paths, name, map/action, title, optionGroup, device, and flags like isBuiltIn, canBeEmpty, isRebindable, isOriginal, allowModifiers, hasConflicts). Used for JSON tooling/UI. -
public bool Equals(ProxyBinding other)
Value equality via Comparer.defaultComparer. -
public override int GetHashCode()
Hash code via Comparer.defaultComparer. -
public static bool PathEquals(ProxyBinding x, ProxyBinding y)
Compare only path (and possibly modifiers depending on allowModifiers) using appropriate comparer. -
public override bool Equals(object obj)
Object equality override; uses Comparer.defaultComparer when obj is ProxyBinding. -
public static bool operator ==(ProxyBinding left, ProxyBinding right)
Equality operator using default comparer. -
public static bool operator !=(ProxyBinding left, ProxyBinding right)
Inequality operator.
Usage Example
// Create a ProxyBinding for an action in code (example)
var proxy = new ProxyBinding("Gameplay", "MoveCamera", ActionComponent.Primary, "up", compositeInstance);
// Set a path and modifiers fluently
proxy = proxy.WithPath("<Keyboard>/w")
.WithModifiers(new[] { new ProxyModifier("<Keyboard>/shift") });
// Check if it's set and whether it conflicts with other registered bindings
if (proxy.isSet) {
var conflicts = proxy.conflicts;
if (proxy.hasConflicts != ProxyBinding.ConflictType.None) {
Debug.Log($"Binding {proxy.title} conflicts with {conflicts.Count} other bindings.");
}
}
// Convert to human readable path for UI
foreach (var human in proxy.ToHumanReadablePath()) {
Debug.Log(human);
}
// Serialize to JSON for a UI / settings dump
using (var writer = JSON.CreateWriter()) {
proxy.Write(writer);
string json = writer.ToString();
Debug.Log(json);
}
Notes:
- Use CreateWatcher(Action