Skip to content

Game.Input.ButtonWithModifiersComposite

Assembly:
Assembly-CSharp (Game runtime assembly; inferred)

Namespace:
Game.Input

Type:
class

Base:
AnalogValueInputBindingComposite

Summary:
A custom input binding composite that represents a primary button ("binding") optionally gated by a modifier button ("modifier"). The composite can operate in analog mode (returning the analog value of the binding) or in button/digital mode (returning 1 when the binding is pressed while the modifier condition is satisfied, otherwise 0). It is annotated for display with a human-readable name and format.


Fields

  • public int binding
    This is the index/name of the primary input control component for the composite. Marked with [InputControl(layout = "Button")], it expects a button-type control.

  • public int modifier
    This is the index/name of the modifier input control component for the composite. Marked with [InputControl(layout = "Button")], it expects a button-type control that must be active for the binding to take effect.

Properties

  • None (no public properties are declared on this type)

Constructors

  • public ButtonWithModifiersComposite()
    Implicit default constructor. The class does not declare an explicit constructor; the default public parameterless constructor is used.

Methods

  • public override float ReadValue(ref InputBindingCompositeContext context)
    Reads the composite's current value from the given InputBindingCompositeContext.
  • Behavior:

    • If the composite is a dummy instance (m_IsDummy from base), returns 0f.
    • If the composite is in analog mode (m_Mode == Mode.Analog from base), it uses CompositeUtility.ReadValue to read an analog float from binding, taking modifier into account and using DefaultComparer.instance.
    • Otherwise (digital/button mode), it evaluates the binding as a button via CompositeUtility.ReadValueAsButton with the modifier; returns 1f when pressed & modifier condition satisfied, otherwise 0f.
  • public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
    Returns the magnitude of the composite. This implementation delegates directly to ReadValue(ref context), so the returned magnitude follows the same analog/digital semantics.

  • public static InputManager.CompositeData GetCompositeData()
    Returns a descriptor describing this composite for registration with the game's input manager. The returned CompositeData encodes the composite type name, the action type (ActionType.Button), and a single component describing the press action with component names "binding" and "modifier". This method is intended for use when registering or enumerating available composites in the game's input system.

Usage Example

// Get metadata for registration with the game's InputManager (API name is illustrative).
var compositeData = ButtonWithModifiersComposite.GetCompositeData();
// Example: register composite data with the game's input manager (method name may vary).
InputManager.RegisterComposite(compositeData);

// Typical runtime usage: when an InputAction using this composite fires, read the value.
// In many input systems the action's callback will reflect the composite result:
private void OnMyActionPerformed(UnityEngine.InputSystem.InputAction.CallbackContext ctx)
{
    // If the action is configured to produce a float (analog or normalized digital),
    // this returns the composite result (0..1 or analog value).
    float value = ctx.ReadValue<float>();
    if (value > 0f)
    {
        // The binding (and modifier requirement) is active.
    }
}

Notes: - The composite relies on helper utilities (CompositeUtility, DefaultComparer) and on base-class state (m_IsDummy, m_Mode) to decide behavior. - The class is annotated with [DisplayStringFormat("{binding}")] and [DisplayName("CO Binding With Modifiers")] to control how it appears in editors or tooling.