Skip to content

Game.Input.Vector2WithModifiersComposite

Assembly: Assembly-CSharp
Namespace: Game.Input

Type: class

Base: AnalogValueInputBindingComposite

Summary: A custom Unity Input System composite that produces a Vector2 value with optional modifier-button behavior. It exposes two component bindings: a "binding" expected to be a Vector2 control (e.g., a joystick or WASD composite) and a "modifier" expected to be a Button control. Depending on the composite's mode (analog vs. button), the composite either returns a raw Vector2 (when in analog mode) or treats the composite as a button (returning Vector2.one when pressed, Vector2.zero when not). The class also supplies metadata for the game's InputManager via GetCompositeData(). The display attributes make the composite appear as "CO Vector 2D With Modifiers" in tooling, and the display string uses the binding name.


Fields

  • public int binding
    This is the index of the Vector2 component binding for the composite. Marked with [InputControl(layout = "Vector2")], so the input layout expects a Vector2-style control (stick, 2D axis, or another composite).

  • public int modifier
    This is the index of the modifier button binding for the composite. Marked with [InputControl(layout = "Button")], so the input layout expects a button-style control (Shift/Ctrl/another key or button).

  • (Inherited/used) m_IsDummy (from base)
    Referenced in ReadValue; if true the composite returns default(Vector2). This is an implementation detail from the base composite class.

  • (Inherited/used) m_Mode (from base)
    Determines whether the composite behaves in Analog mode (returns Vector2) or Button mode (returns Vector2.one/zero).

  • (Inherited/used) base.allowModifiers (from base)
    Passed to CompositeUtility calls to control modifier handling behavior defined by the base class.

Properties

  • This class does not declare own properties. It uses fields and inherited members from its base class.

Constructors

  • public Vector2WithModifiersComposite()
    No explicit constructor is defined in the source; the default parameterless constructor is used.

Methods

  • public override Vector2 ReadValue(ref InputBindingCompositeContext context)
    Reads the composite's current Vector2 value according to composite mode and modifier state.
  • Behavior:

    • If m_IsDummy is true, returns default(Vector2) (i.e., (0,0)).
    • If m_Mode == Mode.Analog, it returns the analog Vector2 value from CompositeUtility.ReadValue, passing the binding index, whether modifiers are allowed, and the modifier index, using Vector2Comparer.instance for comparison.
    • Otherwise (button mode), it treats the bound control as a button: if CompositeUtility.ReadValueAsButton returns false (not pressed), it returns Vector2.zero; if pressed, returns Vector2.one.
  • public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
    Returns the magnitude (length) of the Vector2 returned by ReadValue. Useful for action thresholding and value comparisons.

  • public static InputManager.CompositeData GetCompositeData()
    Returns an InputManager.CompositeData that describes this composite to the game's InputManager. The returned CompositeData:

  • Uses CompositeUtility.GetCompositeTypeName(typeof(Vector2WithModifiersComposite)) as the composite type name.
  • Sets the ActionType to Button.
  • Defines one CompositeComponentData mapping ActionComponent.Press to the "binding" component with "modifier" as its modifier.

Usage Example

  • Registering the composite with Unity's Input System (typical pattern; may be done at startup of the mod/game):
// Register the composite type with the input system (do this during initialization)
UnityEngine.InputSystem.InputSystem.RegisterBindingComposite<Game.Input.Vector2WithModifiersComposite>();

// Example input action reading (assuming an InputAction that uses this composite)
void OnMyActionPerformed(UnityEngine.InputSystem.InputAction.CallbackContext ctx)
{
    // If the action is configured to use this composite, you can read the Vector2 value:
    var value = ctx.ReadValue<UnityEngine.Vector2>();
    // Use value (in button-mode it will be Vector2.zero or Vector2.one; in analog mode the actual Vector2)
}
  • Example of how it behaves conceptually:
  • Analog mode: returns the actual Vector2 from the bound "binding" control, optionally modified by the modifier depending on base.allowModifiers and CompositeUtility behavior.
  • Button mode: returns Vector2.one when the modifier + binding are considered pressed, otherwise Vector2.zero.

Notes: - The class relies on base-class members and CompositeUtility helpers; behavior for modifier handling and "mode" comes from the inherited AnalogValueInputBindingComposite implementation. - The DisplayName attribute makes this composite appear as "CO Vector 2D With Modifiers" in any UI that respects DisplayName. The DisplayStringFormat attribute formats how the composite is shown (using "{binding}").