Skip to content

Game.Input.AxisSeparatedWithModifiersComposite

Assembly:
Assembly-CSharp (typical for mod scripts; class originates from the mod/game project)

Namespace:
Game.Input

Type:
class

Base:
AnalogValueInputBindingComposite (UnityEngine.InputSystem)

Summary:
A custom Unity Input System composite that composes two separate inputs (negative and positive) each optionally gated by a modifier button to produce a single axis value between m_MinValue and m_MaxValue. It supports both analog and digital (button) modes depending on the inherited m_Mode. When both sides are active the composite resolves the conflict using the m_WhichSideWins enum (Positive, Negative, or Neither). The neutral output is the midpoint between m_MinValue and m_MaxValue.


Fields

  • public int negative
    Input binding index for the negative side. Marked with [InputControl(layout = "Button")]. This represents the input (button or analog) that drives the negative direction.

  • public int positive
    Input binding index for the positive side. Marked with [InputControl(layout = "Button")]. This represents the input (button or analog) that drives the positive direction.

  • public int negativeModifier
    Input binding index for an optional modifier for the negative input. Marked with [InputControl(layout = "Button")]. If provided and m_AllowModifiers is used, the negative input is only considered when its modifier condition is satisfied.

  • public int positiveModifier
    Input binding index for an optional modifier for the positive input. Marked with [InputControl(layout = "Button")]. Works like negativeModifier but for the positive side.

  • public float m_MinValue = -1f
    Minimum axis value produced when the negative side is fully active. Default -1.

  • public float m_MaxValue = 1f
    Maximum axis value produced when the positive side is fully active. Default +1.

  • public WhichSideWins m_WhichSideWins
    Conflict-resolution enum instance. When both negative and positive are active, determines which side wins:

  • Neither — return midpoint (no side wins)
  • Positive — positive side wins
  • Negative — negative side wins

Note: The composite also relies on inherited/internal members from the base class (for example m_Mode, m_IsDummy, and m_AllowModifiers) to determine read semantics (analog vs button) and modifier handling.

Properties

  • public float midPoint => (m_MaxValue + m_MinValue) / 2f
    Returns the neutral midpoint of the axis, i.e., the value returned when neither side is pressed/active or when a tie is resolved to Neither. By default (m_MinValue = -1, m_MaxValue = 1) this is 0.

Constructors

  • public AxisSeparatedWithModifiersComposite()
    The default constructor (implicit). When instantiated the fields inherit their declared defaults (m_MinValue = -1f, m_MaxValue = 1f). No custom initialization is defined in the class.

Methods

  • public override float ReadValue(ref InputBindingCompositeContext context)
    Reads the composite and returns a float axis value between m_MinValue and m_MaxValue.

Behavior summary: - If the composite is a dummy (m_IsDummy) it returns 0. - If the composite's mode (m_Mode) is Analog, it reads absolute analog values from negative/positive (taking modifiers into account if m_AllowModifiers is set) using CompositeUtility.ReadValue. - Otherwise (digital mode), it reads the inputs as buttons using CompositeUtility.ReadValueAsButton and converts to 1.0 or 0.0. - It compares values to Mathf.Epsilon to determine whether negative and/or positive are active. - If both are active, it resolves the conflict using m_WhichSideWins: - Negative: positive is ignored. - Positive: negative is ignored. - Neither: returns midpoint. - If negative is active, returns value linearly interpolated from midpoint toward m_MinValue scaled by the negative input magnitude. - If positive is active, returns value linearly interpolated from midpoint toward m_MaxValue scaled by the positive input magnitude. - If neither side is active returns midpoint.

  • public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
    Computes the magnitude of the composite output relative to the midpoint and normalizes it to the range [0,1] using NormalizeProcessor.Normalize:
  • Reads the composite value using ReadValue.
  • Computes absolute distance from midpoint.
  • If the value is below midpoint, normalizes against Abs(m_MinValue).
  • If above midpoint, normalizes against Abs(m_MaxValue).
  • Returns the normalized magnitude (0 = at midpoint, 1 = fully at min or max value).

  • public static InputManager.CompositeData GetCompositeData()
    Returns an InputManager.CompositeData describing this composite for registration purposes. The returned composite has ActionType.Axis and two components:

  • Negative component with keys "negative" and "negativeModifier".
  • Positive component with keys "positive" and "positiveModifier".

Note: InputManager and CompositeData appear to be part of the project-specific input registration layer; this helper simplifies registering or describing the composite within that system.

Usage Example

// Register the composite (do this during initialization)
UnityEngine.InputSystem.InputSystem.RegisterBindingComposite<AxisSeparatedWithModifiersComposite>();

// Example: create an InputAction and add a composite binding for left/right with shift modifiers
var action = new UnityEngine.InputSystem.InputAction("MoveHorizontal", UnityEngine.InputSystem.InputActionType.Value);

// Use the display name or the composite name; here we use the display name defined on the class.
// Depending on your setup you can also pass the class name directly.
action.AddCompositeBinding("CO Positive/Negative Binding With Modifiers")
      .With("negative", "<Keyboard>/a")
      .With("negativeModifier", "<Keyboard>/leftShift")   // optional
      .With("positive", "<Keyboard>/d")
      .With("positiveModifier", "<Keyboard>/rightShift"); // optional

action.performed += ctx => {
    float value = ctx.ReadValue<float>();
    UnityEngine.Debug.Log($"Axis value: {value}");
};

action.Enable();

Additional notes: - The composite supports both analog and button semantics depending on the inherited m_Mode (Analog mode reads analog magnitudes; button mode treats inputs as 0/1). - For two simultaneously pressed sides, use m_WhichSideWins to control behavior (Positive, Negative, or Neither to return midpoint). - Typical defaults produce a midpoint of 0 (m_MinValue = -1, m_MaxValue = 1). Adjust m_MinValue/m_MaxValue to scale axis range as needed.