Game.Input.ProxyModifier
Assembly: Game
Namespace: Game.Input
Type: struct
Base: System.ValueType, System.IEquatable
Summary: Represents a single input "modifier" used by the input system (for example Shift, Ctrl, Alt or specific gamepad stick presses). A ProxyModifier stores a human-readable name, the input control path (m_Path) and a reference to an ActionComponent (m_Component). The type includes equality/ordering support via a nested Comparer class which can compare by name, path and/or component index and contains a small built-in ordering table for common modifier paths (e.g. keyboard modifiers first, then certain gamepad controls). The m_Component field is marked with [Exclude], indicating it is excluded from JSON serialization by Colossal.Json.
Fields
-
public ActionComponent m_Component
Holds a reference to an ActionComponent associated with this modifier. Marked with [Exclude] (Colossal.Json) so it won't be serialized. Used by runtime code to tie the modifier back to its runtime action/component. -
public string m_Name
Human readable name for the modifier (for example "Shift"). -
public string m_Path
The input control path string (for example "/shift" or " /leftStickPress"). Used by Comparer and input matching logic. -
public static Comparer pathComparer
Preconfigured Comparer instance that compares only by path (Comparer.Options.Path). Useful when ordering or deduplicating modifiers based on control path only.
Properties
public static Comparer defaultComparer { get; }
Returns the default Comparer instance (Comparer.defaultComparer) which is preconfigured to compare by Path and Component (the Comparer default uses Options.Path | Options.Component). Use this for consistent equality and hashing behavior across collections.
Constructors
-
public ProxyModifier()
No explicit constructors are defined in the source; the struct uses the implicit parameterless constructor provided by C#. Fields (m_Name, m_Path, m_Component) are default-initialized. -
public Comparer(Comparer.Options options = Comparer.Options.Path | Comparer.Options.Component)
(nested class)
Comparer constructor that allows configuring which fields (Name, Path, Component) should be considered for equality, hashing and ordering.
Methods
-
public override string ToString()
Returns a string combining the name and path, formatted as: "{m_Name} - {m_Path}". Useful for debugging and logging. -
public bool Equals(ProxyModifier other)
Implements IEquatable. Uses Comparer.defaultComparer to determine equality (comparing configured fields — by default Path and Component). -
public override int GetHashCode()
Computes a hash code using Comparer.defaultComparer. Only the fields enabled in the Comparer are added to the hash (by default Path and Component). -
public override bool Equals(object obj)
Type-safe override that returns true when obj is a ProxyModifier and Equals(ProxyModifier) is true. -
public static bool operator ==(ProxyModifier left, ProxyModifier right)
Equality operator that forwards to Equals. -
public static bool operator !=(ProxyModifier left, ProxyModifier right)
Inequality operator that negates Equals.
Nested type: Comparer (class)
- Purpose: Provides equality, hashing and ordering logic for ProxyModifier instances. It supports Options flags:
- Name: include m_Name
- Path: include m_Path
- Component: include m_Component
- Notable internals:
- sOrder: a small Dictionarybool Equals(ProxyModifier x, ProxyModifier y)
— compares enabled fields.
- int GetHashCode(ProxyModifier modifier)
— computes hash by adding enabled fields.
- int Compare(ProxyModifier x, ProxyModifier y)
— returns ordering based on enabled fields and sOrder precedence when comparing paths.
- Predefined instances:
- Comparer.defaultComparer
— a Comparer configured with the default options (Path | Component).
- Comparer pathComparer
(exposed on the struct) — a Comparer configured with Options.Path.
Usage Example
// Create modifiers
ProxyModifier modShift = new ProxyModifier {
m_Name = "Shift",
m_Path = "<Keyboard>/shift",
m_Component = someActionComponent
};
ProxyModifier modCtrl = new ProxyModifier {
m_Name = "Ctrl",
m_Path = "<Keyboard>/ctrl",
m_Component = someOtherActionComponent
};
// Compare for equality using the default comparer (Path | Component)
bool equal = modShift.Equals(modCtrl);
// Use as keys in a HashSet with a Comparer (Path-only)
var set = new HashSet<ProxyModifier>(ProxyModifier.pathComparer);
set.Add(modShift);
set.Add(modCtrl);
// Sort a list using the default comparer (which respects sOrder for known paths)
var list = new List<ProxyModifier> { modCtrl, modShift };
list.Sort(ProxyModifier.defaultComparer); // Uses Comparer.Compare
// Debug print
foreach (var m in list)
{
Console.WriteLine(m.ToString()); // "Shift - <Keyboard>/shift"
}
Notes: - The m_Component field is marked with [Exclude] and typically references runtime action/component data that should not be serialized to JSON. - Use the Comparer.Options flags when you need different equality semantics (for example, to deduplicate modifiers by Path only, use a Comparer configured with Options.Path).