Game.Input.InputExtension
Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mods)
Namespace:
Game.Input
Type:
public static class
Base:
System.Object
Summary:
A collection of extension methods used to convert between Unity InputSystem types (InputBinding, binding groups, control schemes) and the game's InputManager.DeviceType / InputManager.ControlScheme enums, plus helpers to map ActionComponent values to UIBaseInputAction.Transform and to fetch binding path/processors/interactions for different PathType selections. These helpers centralize the mapping logic used by the game's input layer and make it easier to translate between Unity bindings and the game's internal device/type flags.
Fields
- None
This static helper class does not declare any instance or static fields.
Properties
- None
No properties are declared on this static class.
Constructors
- None
Static classes have no constructors exposed; all members are static.
Methods
public static InputManager.DeviceType ToDeviceType(this InputBinding? mask)
Converts an optional InputBinding mask to an InputManager.DeviceType bitflag.- Behavior:
- If mask is null, returns DeviceType.All.
- Starts with DeviceType.None and ORs in Keyboard/Mouse/Gamepad when the mask.groups string contains "Keyboard", "Mouse" or "Gamepad" respectively.
-
Notes: The method does a substring Contains against binding.groups; it relies on the exact group names used elsewhere ("Keyboard", "Mouse", "Gamepad").
-
public static InputManager.DeviceType ToDeviceType(this string group)
Converts a binding group name to a single InputManager.DeviceType. Supported group strings: - "Keyboard" => DeviceType.Keyboard
- "Mouse" => DeviceType.Mouse
- "Gamepad", "DualShockGamepad", "XInputController" => DeviceType.Gamepad
- Throws ArgumentException for unsupported strings.
-
Use this to interpret a single group name.
-
public static InputManager.DeviceType ToDeviceType(this InputManager.ControlScheme scheme)
Maps a ControlScheme enum to DeviceType: - KeyboardAndMouse => Keyboard | Mouse
- Gamepad => Gamepad
-
default => None
-
public static InputBinding? ToInputBinding(this InputManager.DeviceType type)
Converts a DeviceType value back into an InputBinding mask (using InputBinding.MaskByGroups / MaskByGroup): - DeviceType.All => null (meaning no mask / matches all)
- DeviceType.None => MaskByGroup(string.Empty) (an explicit empty group mask)
- Otherwise builds a mask including "Keyboard", "Mouse", and/or "Gamepad" depending on which bits are set.
-
Note: Uses InputBinding.MaskByGroups to produce a binding mask string for the requested groups.
-
public static UIBaseInputAction.Transform ToTransform(this ActionComponent component)
Maps ActionComponent enum values to UIBaseInputAction.Transform values. Common mappings: - Press -> Press
- Negative -> Negative
- Positive -> Positive
- Down -> Down
- Up -> Up
- Left -> Left
- Right -> Right
-
default -> Press
-
public static string GetPath(this InputBinding binding, InputManager.PathType pathType)
Returns the binding path string depending on the requested PathType: - Effective => binding.effectivePath
- Original => binding.path
- Overridden => binding.overridePath
-
default => binding.effectivePath
-
public static string GetProcessors(this InputBinding binding, InputManager.PathType pathType)
Returns the binding processors string depending on PathType: - Effective => binding.effectiveProcessors
- Original => binding.processors
- Overridden => binding.overrideProcessors
-
default => binding.effectivePath (note: default returns effectivePath in the source; this looks like a likely copy-paste bug — it probably should return binding.effectiveProcessors)
-
public static string GetInteractions(this InputBinding binding, InputManager.PathType pathType)
Returns the binding interactions string depending on PathType: - Effective => binding.effectiveInteractions
- Original => binding.interactions
- Overridden => binding.overrideInteractions
- default => binding.effectivePath (note: as above, returning effectivePath in the default branch is likely unintended and probably should be binding.effectiveInteractions)
Usage Example
// Convert an InputBinding? to DeviceType
InputBinding? bindingMask = InputBinding.MaskByGroups("Keyboard", "Mouse");
InputManager.DeviceType device = bindingMask.ToDeviceType(); // Keyboard | Mouse
// Convert a group name to a DeviceType
InputManager.DeviceType fromGroup = "Gamepad".ToDeviceType(); // Gamepad
// Convert a ControlScheme to DeviceType
InputManager.DeviceType fromScheme = InputManager.ControlScheme.KeyboardAndMouse.ToDeviceType(); // Keyboard | Mouse
// Convert DeviceType back to InputBinding mask
InputBinding? maskBack = (InputManager.DeviceType.Keyboard | InputManager.DeviceType.Gamepad).ToInputBinding();
// Map an ActionComponent to UI transform
UIBaseInputAction.Transform t = ActionComponent.Down.ToTransform();
// Get the effective path/processors/interactions from a binding
string path = someBinding.GetPath(InputManager.PathType.Effective);
string processors = someBinding.GetProcessors(InputManager.PathType.Effective);
string interactions = someBinding.GetInteractions(InputManager.PathType.Effective);
Notes: - This class bridges Unity's InputSystem representation and the game's own input enums (InputManager.* and UIBaseInputAction). When updating or refactoring input group names or PathType handling, ensure consistency with these helpers. - The default branches of GetProcessors and GetInteractions currently return binding.effectivePath in the original source; consider correcting those to return the corresponding effective processors/interactions if that was unintended.