Game.Input.ControlPath
Assembly: Assembly-CSharp
Namespace: Game.Input
Type: struct
Base: System.ValueType, IJsonWritable
Summary:
ControlPath is a lightweight value type used to represent a parsed input control path (from Unity Input System) in a compact form for the game's input system and UI. It extracts the logical "name" (joined control names), the input device type, and a display-friendly label. It also contains helpers to determine when a key's name should be localized based on keyboard layout and to serialize the struct to JSON.
Fields
-
private static System.Collections.Generic.Dictionary<string, bool> m_IsLatinLayout
Stores a cache mapping keyboard layout identifiers to a boolean indicating whether that layout is "Latin-like" (used to decide if keys should use a localized name or a generic one). -
public string name
The parsed control name produced by joining path components (e.g., "a" or "space"). This is the logical path fragment(s) without layout qualifiers. -
public InputManager.DeviceType device
Device type inferred from the control path layout (converted via layout.ToDeviceType()). Identifies the input device (keyboard, mouse, gamepad, etc.). -
public string displayName
A display-friendly label for the control. If the name is a single letter, it is uppercased; otherwise the name is used as-is.
Properties
- None (this struct exposes public fields and static helpers; there are no C# properties defined).
Constructors
public ControlPath()
Implicit default struct constructor is available; most instances are created via the static Get(string path) factory which parses an input control path.
Methods
-
public static ControlPath Get(string path)
Parses a Unity InputControlPath string using InputControlPath.Parse, builds the compactname
by joining components that do not specify a layout, finds the first layout to determinedevice
(via ToDeviceType), and setsdisplayName
(single-letter names are uppercased). Returns an "empty" ControlPath when path is null or empty. -
public static bool IsLatinLikeLayout(UnityEngine.InputSystem.Keyboard keyboard)
Checks whether the keyboard layout is "Latin-like". Uses a cached dictionary (m_IsLatinLayout); if not cached, it tests a range of key display names (letters A–Z range) to ensure they are Latin letters or punctuation. The result is cached per keyboard layout string. -
public static bool NeedLocalName(UnityEngine.InputSystem.Keyboard keyboard, UnityEngine.InputSystem.Controls.KeyControl control)
Determines whether a particular KeyControl should use a localized name. For many keys (space, enter, digits, modifiers, arrows, navigation keys, numpad keys, etc.) the method returns false (no localization is needed). For OEM keys (OEM1..OEM5) it returns true (local name recommended). For other keys it falls back to IsLatinLikeLayout to decide. -
private static bool IsLatinOrPunctuation(string displayName)
Helper that returns true if the displayName starts with a Latin letter/digit (within Latin-1 range) or if the first character is punctuation (fallback). Returns false for null/empty strings. -
private static bool IsLatinLater(string displayName)
Checks whether the first character of displayName is a letter or digit and falls within the Latin-1 character range (character code <= 'ÿ'). Used by IsLatinOrPunctuation. -
public void Write(IJsonWriter writer)
Serializes this ControlPath to JSON using an IJsonWriter. It writes the CLR type name, then properties "name", "device" (as string), and "displayName", and ends the type. -
public static string ToHumanReadablePath(string path, InputControlPath.HumanReadableStringOptions options = InputControlPath.HumanReadableStringOptions.OmitDevice)
A thin wrapper around InputControlPath.ToHumanReadableString to convert an input control path to a human-readable string, with a default option to omit device text.
Usage Example
// Parse a control path and use it
ControlPath cp = ControlPath.Get("<Keyboard>/a"); // name = "a", device = Keyboard, displayName = "A"
var human = ControlPath.ToHumanReadablePath("<Keyboard>/a"); // e.g. "A"
// Decide whether to show a localized label for a key at runtime
// (requires UnityEngine.InputSystem APIs and a KeyControl instance)
bool needLocal = ControlPath.NeedLocalName(Keyboard.current, Keyboard.current.aKey);
// Serialize to JSON via an IJsonWriter implementation
// writer is assumed to be an existing IJsonWriter
cp.Write(writer);