Game.Vector2SeparatedWithModifiersComposite
Assembly: Assembly-CSharp
Namespace: Game.Input
Type: class
Base: AnalogValueInputBindingComposite
Summary: A custom Input System composite that maps separate up/down/left/right controls — each with an optional modifier — into a single Vector2 value (D-pad style). The composite supports both analog and digital modes (inherited from the base) and returns a Vector2 constructed via DpadControl.MakeDpadVector. Each component is declared as an input control index (int) and annotated with an InputControl attribute for button layout. The composite exposes a static GetCompositeData helper used by the game's InputManager to describe the composite and its components.
Fields
-
public int up
Registers the "up" component index for the composite. Annotated with [InputControl(layout = "Button")]. When read, this represents the positive Y direction input. -
public int down
Registers the "down" component index for the composite. Annotated with [InputControl(layout = "Button")]. When read, this represents the negative Y direction input. -
public int left
Registers the "left" component index for the composite. Annotated with [InputControl(layout = "Button")]. When read, this represents the negative X direction input. -
public int right
Registers the "right" component index for the composite. Annotated with [InputControl(layout = "Button")]. When read, this represents the positive X direction input. -
public int upModifier
Optional modifier binding index for the "up" component. Annotated with [InputControl(layout = "Button")]. Used when m_AllowModifiers is enabled to require/consider a modifier when reading the component. -
public int downModifier
Optional modifier binding index for the "down" component. Annotated with [InputControl(layout = "Button")]. -
public int leftModifier
Optional modifier binding index for the "left" component. Annotated with [InputControl(layout = "Button")]. -
public int rightModifier
Optional modifier binding index for the "right" component. Annotated with [InputControl(layout = "Button")].
Notes: - The integer fields are indices used by Unity's InputBindingCompositeContext/CompositeUtility to read the actual control values. - This composite relies on inherited members such as m_Mode (Analog / Digital / DigitalNormalized), m_AllowModifiers, and m_IsDummy from the base class to control behavior.
Properties
- (No public properties are declared in this class. The class overrides behavior of the base composite but does not introduce new C# properties.)
Constructors
public Vector2SeparatedWithModifiersComposite()
Implicit default constructor. No custom initialization is required by the composite; configuration is done via the public component fields.
Methods
public override UnityEngine.Vector2 ReadValue(ref UnityEngine.InputSystem.InputBindingCompositeContext context)
Reads the composite value from the given context. Behavior:- If m_IsDummy is true, returns default(Vector2).
- If m_Mode == Mode.Analog: reads float values for each direction (up/down/left/right) using CompositeUtility.ReadValue with the corresponding modifier indices (if m_AllowModifiers is true) and returns a vector produced by DpadControl.MakeDpadVector(float up, float down, float left, float right).
-
Otherwise (digital modes): reads each direction as button states using CompositeUtility.ReadValueAsButton (respecting modifiers) and returns a vector produced by DpadControl.MakeDpadVector(bool up, bool down, bool left, bool right, bool normalize) where normalize is true for Mode.DigitalNormalized.
-
public override float EvaluateMagnitude(ref UnityEngine.InputSystem.InputBindingCompositeContext context)
Returns the magnitude of the vector produced by ReadValue. Typically used by the Input System to determine the action's effective magnitude for processing in analog/digital contexts. -
public static InputManager.CompositeData GetCompositeData()
Creates and returns an InputManager.CompositeData instance describing this composite to the game's InputManager. The returned CompositeData: - Uses the composite type name resolved from the class type.
- Declares an ActionType.Vector2 composite.
- Defines four components in the order Up, Down, Left, Right, each pairing the control name and its modifier name (e.g., "up" with "upModifier").
Additional notes: - The class is annotated with [DisplayStringFormat("{up}/{left}/{down}/{right}")] and [DisplayName("CO Up/Down/Left/Right Binding With Modifiers")] which affect how the composite is shown in UIs or editors.
Usage Example
// Register the composite with the Input System (do this once on startup)
UnityEngine.InputSystem.InputSystem.RegisterBindingComposite<Game.Input.Vector2SeparatedWithModifiersComposite>();
// Example InputAction setup in code (or assign via editor):
// Action expected to be of type Vector2 and use a binding that references this composite.
// Reading value from an action:
void Update()
{
// Assume `moveAction` is an InputAction of type Vector2 using this composite
UnityEngine.Vector2 move = moveAction.ReadValue<UnityEngine.Vector2>();
// Use move.x, move.y for movement or UI navigation
}
// If the game uses a custom InputManager and expects CompositeData:
var compositeData = Game.Input.Vector2SeparatedWithModifiersComposite.GetCompositeData();
// compositeData can be passed to the game's InputManager to register/describe the composite.
{{ This composite allows modders to create a D-pad or WASD-like mapping where each direction can optionally require a separate modifier input. It integrates with the game's InputManager via GetCompositeData and with the Unity Input System when registered with InputSystem.RegisterBindingComposite. When choosing between analog and digital behavior, rely on the inherited m_Mode from the base composite (Analog vs Digital vs DigitalNormalized). }}