Game.Input.AxisWithModifiersComposite
Assembly: Assembly-CSharp (typical for Cities: Skylines 2 mods)
Namespace: Game.Input
Type: class
Base: AnalogValueInputBindingComposite
Summary:
A custom input binding composite that reads a single 1D axis value but supports an optional modifier button. When configured in "Analog" mode the composite returns the axis value directly (respecting modifiers if allowed). When not in analog mode (i.e., treated as a button), the composite returns 1.0 when the axis is considered "pressed" (via CompositeUtility.ReadValueAsButton) and 0 otherwise. The class is decorated with DisplayStringFormat and DisplayName attributes to present nicely in input configuration UIs.
Fields
-
public int binding
Attribute: [InputControl(layout = "Axis")]
Index of the axis component in the composite. This maps to the axis control to be read by the composite (e.g., a joystick axis or trigger). The integer is the index of the component slot within the composite, not the control path itself. -
public int modifier
Attribute: [InputControl(layout = "Button")]
Index of the modifier button component. When present, the modifier can alter how the axis is interpreted (for example, require the modifier to be held for the axis to be considered active when in button mode).
Properties
- None declared in this class. (The class uses inherited members such as m_IsDummy, m_Mode and base.allowModifiers from its base class.)
Constructors
public AxisWithModifiersComposite()
No explicit constructor is defined in the source; the default parameterless constructor is used.
Methods
public override float ReadValue(ref InputBindingCompositeContext context)
Reads the composite's value according to the current mode and modifier state.- Behavior:
- If the composite is a dummy (m_IsDummy is true) returns 0f.
- If m_Mode == Mode.Analog: returns the axis value via CompositeUtility.ReadValue(...), passing base.allowModifiers and the modifier index so modifiers can be applied if allowed.
- Otherwise (button mode): evaluates the axis as a button via CompositeUtility.ReadValueAsButton(...). If that returns true returns 1f, otherwise 0f.
- Parameters:
- context: InputBindingCompositeContext passed in by the InputSystem when reading the composite.
-
Returns:
- A float representing the axis value in analog mode, or 1/0 in button mode.
-
public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
Returns the magnitude of the composite value. Implementation returns Mathf.Abs(ReadValue(ref context)). - Parameters:
- context: InputBindingCompositeContext.
-
Returns:
- Absolute value of the composite's read value (float).
-
public static InputManager.CompositeData GetCompositeData()
Creates and returns an InputManager.CompositeData describing this composite for the game's input manager. - Behavior:
- Uses CompositeUtility.GetCompositeTypeName(typeof(AxisWithModifiersComposite)) to obtain the composite type name.
- Specifies ActionType.Button and a single composite component: ActionComponent.Press with component names "binding" and "modifier".
- Returns:
- InputManager.CompositeData suitable for registration/consumption by the game input manager.
Usage Example
// Register the composite with the Input System (do this during input setup)
// using UnityEngine.InputSystem;
InputSystem.RegisterBindingComposite<Game.Input.AxisWithModifiersComposite>();
// Example pseudo-usage in an input read callback (the composite is used by the Input System automatically)
protected override float ReadValue(ref InputBindingCompositeContext context)
{
// Implementation from AxisWithModifiersComposite:
// - returns 0 if the composite is a dummy
// - returns analog axis value if in Analog mode
// - otherwise returns 1 or 0 depending on whether the axis is considered pressed
return base.ReadValue(ref context);
}
Notes and tips:
- The fields are index-based component slots (typical for Unity Input System composites) and are annotated with InputControl attributes to suggest layout types in authoring tools.
- The composite defers comparison and press semantics to CompositeUtility and DefaultComparer