Class ButtonWithTwoModifiers | Input System | 1.0.2
docs.unity3d.com
    Show / Hide Table of Contents

    Class ButtonWithTwoModifiers

    A button with two additional modifiers. The button only triggers when both modifiers are pressed.

    Inheritance
    Object
    InputBindingComposite
    InputBindingComposite<Single>
    ButtonWithTwoModifiers
    Inherited Members
    InputBindingComposite<Single>.valueType
    InputBindingComposite<Single>.valueSizeInBytes
    InputBindingComposite<Single>.ReadValue(InputBindingCompositeContext, Void*, Int32)
    InputBindingComposite<Single>.ReadValueAsObject(InputBindingCompositeContext)
    InputBindingComposite.GetExpectedControlLayoutName(String, String)
    Namespace: UnityEngine.InputSystem.Composites
    Syntax
    [Preserve]
    [DisplayStringFormat("{modifier1}+{modifier2}+{button}")]
    public class ButtonWithTwoModifiers : InputBindingComposite<float>
    Remarks

    This composite can be used to require two other buttons to be held while pressing the button that triggers the action. This is most commonly used on keyboards to require two of the modifier keys (shift, ctrl, or alt) to be held in combination with another key, e.g. "CTRL+SHIFT+1".

    // Create a button action that triggers when CTRL+SHIFT+1
    // is pressed on the keyboard.
    var action = new InputAction(type: InputActionType.Button);
    action.AddCompositeBinding("ButtonWithTwoModifiers")
        .With("Modifier1", "<Keyboard>/leftCtrl")
        .With("Modifier1", "<Keyboard>/rightCtrl")
        .With("Modifier2", "<Keyboard>/leftShift")
        .With("Modifier2", "<Keyboard>/rightShift")
        .With("Button", "<Keyboard>/1")

    Note that this is not restricted to the keyboard and will preserve the full value of the button.

    // Create a button action that requires the A and X button on the
    // gamepad to be held and will then trigger from the gamepad's
    // left trigger button.
    var action = new InputAction(type: InputActionType.Button);
    action.AddCompositeBinding("ButtonWithTwoModifiers")
        .With("Modifier1", "<Gamepad>/buttonSouth")
        .With("Modifier2", "<Gamepad>/buttonWest")
        .With("Button", "<Gamepad>/leftTrigger");

    Fields

    button

    Binding for the button that is gated by the modifier1 and modifier2. The composite will assume the value of this button while both of the modifiers are pressed.

    Declaration
    public int button
    Field Value
    Type Description
    Int32

    Part index to use with ReadValue<TValue>(Int32).

    Remarks

    This property is automatically assigned by the input system.

    modifier1

    Binding for the first button that acts as a modifier, e.g. <Keyboard/leftCtrl.

    Declaration
    public int modifier1
    Field Value
    Type Description
    Int32

    Part index to use with ReadValue<TValue>(Int32).

    Remarks

    This property is automatically assigned by the input system.

    modifier2

    Binding for the second button that acts as a modifier, e.g. <Keyboard/leftCtrl.

    Declaration
    public int modifier2
    Field Value
    Type Description
    Int32

    Part index to use with ReadValue<TValue>(Int32).

    Remarks

    This property is automatically assigned by the input system.

    Methods

    EvaluateMagnitude(ref InputBindingCompositeContext)

    Same as ReadValue(ref InputBindingCompositeContext) in this case.

    Declaration
    public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context

    Evaluation context passed in from the input system.

    Returns
    Type Description
    Single

    A >0 value if the composite is currently actuated.

    Overrides
    InputBindingComposite.EvaluateMagnitude(ref InputBindingCompositeContext)

    ReadValue(ref InputBindingCompositeContext)

    Return the value of the button part while both modifier1 and modifier2 are pressed. Otherwise return 0.

    Declaration
    public override float ReadValue(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context

    Evaluation context passed in from the input system.

    Returns
    Type Description
    Single

    The current value of the composite.

    Overrides
    UnityEngine.InputSystem.InputBindingComposite<System.Single>.ReadValue(UnityEngine.InputSystem.InputBindingCompositeContext)

    See Also

    ButtonWithOneModifier
    In This Article
    • Fields
      • button
      • modifier1
      • modifier2
    • Methods
      • EvaluateMagnitude(ref InputBindingCompositeContext)
      • ReadValue(ref InputBindingCompositeContext)
    • See Also
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023