Skip to content

Game.CameraVector2WithModifiersComposite

Assembly: Assembly-CSharp
Namespace: Game.Input

Type: class

Base: AnalogValueInputBindingComposite

Summary:
A Unity Input System composite that reads a 2D vector for camera controls while supporting a modifier/button ("trigger"). The composite can operate in analog mode (reading an actual Vector2 value) or in button mode (treating the vector as a boolean press). It also supports an option where the modifier/button itself actuates (controls) the returned magnitude.


Fields

  • public bool m_ModifierActuatesControl
    Controls whether the modifier/button input itself drives the magnitude returned by EvaluateMagnitude. If true and a trigger binding is present, magnitude is derived from the trigger's analog value (absolute float).

  • [InputControl(layout = "Vector2")] public int vector
    Index/slot for the Vector2 input control (e.g., stick or mouse delta). This is the main directional input for the composite.

  • [InputControl(layout = "Button")] public int trigger
    Index/slot for the modifier/button control. Used to gate or modify the vector input (e.g., a shift key, trigger button). When used with button-mode behavior, the trigger acts as the boolean that determines whether the composite is considered pressed.

Notes: The composite relies on inherited fields such as m_IsDummy and m_Mode (from the base class) to decide behavior and to support dummy/no-op composites.

Properties

  • (none declared on this type)
    This composite does not declare any public C# properties; it exposes its configuration via public fields used by the Input System attribute-driven binding.

Constructors

  • public CameraVector2WithModifiersComposite()
    Default parameterless constructor (implicit in source). No special initialization is performed by the type itself.

Methods

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

Behavior summary: - If the composite is marked as a dummy (m_IsDummy), returns default(Vector2). - If the composite's mode is Mode.Analog, returns the Vector2 read via CompositeUtility.ReadValue(..., allowModifiers: true, trigger, Vector2Comparer.instance). This will allow modifier(s) to influence the read. - Otherwise (button mode): uses CompositeUtility.ReadValueAsButton(..., allowModifiers: true, trigger). If that returns false, returns Vector2.zero; if true, returns Vector2.one. This converts the composite to a simple pressed/not-pressed Vector2 result.

  • public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
    Evaluates the magnitude of the composite for purposes such as action processing or deadzone handling.

Behavior summary: - First checks modifiers via CompositeUtility.CheckModifiers(..., allowModifiers: true, trigger). If the modifier check fails, returns 0f. - If m_ModifierActuatesControl is true and a trigger binding is present, returns the absolute value of the trigger's analog read (context.ReadValue(trigger)). - Otherwise returns context.EvaluateMagnitude(vector) (magnitude of the underlying vector binding). - If modifiers fail, returns 0f.

  • public static InputManager.CompositeData GetCompositeData()
    Constructs and returns an InputManager.CompositeData instance describing this composite for use by the game's input manager. The composite is reported as an ActionType.Button with a single component describing the "trigger" press component. This is used for composite registration and integration with the game's input handling pipeline.

Usage Example

// Register the composite once during startup (so the Input System knows the composite type)
InputSystem.RegisterBindingComposite<CameraVector2WithModifiersComposite>();

// Example: create an input action that uses the composite
var action = new InputAction("CameraMove", InputActionType.Value);

// Add a composite binding by the display name (matches [DisplayName])
action.AddCompositeBinding("CO Camera Vector 2D With Modifiers")
      .With("vector", "<Gamepad>/rightStick")    // main Vector2 input
      .With("trigger", "<Keyboard>/leftShift");  // modifier/button

action.Enable();

// Read value in a callback
void OnCameraMove(InputAction.CallbackContext ctx)
{
    Vector2 cameraInput = ctx.ReadValue<Vector2>();
    // cameraInput will be Vector2.zero or Vector2.one in button-mode,
    // or the actual vector (possibly modified) in analog mode.
}

Additional notes: - The composite integrates with CompositeUtility helpers and expects comparers such as Vector2Comparer and ModifiersComparer (used internally when reading and evaluating).
- Use m_ModifierActuatesControl when you want the modifier's analog value to control the returned magnitude (for example, when a trigger's pressure should scale camera movement).