docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TwoModifiersComposite

    A binding with two additional modifiers modifier. The bound controls only trigger when both modifiers are pressed.

    Inheritance
    object
    InputBindingComposite
    TwoModifiersComposite
    Inherited Members
    InputBindingComposite.GetExpectedControlLayoutName(string, string)
    Namespace: UnityEngine.InputSystem.Composites
    Assembly: Unity.InputSystem.dll
    Syntax
    [DisplayStringFormat("{modifier1}+{modifier2}+{binding}")]
    public class TwoModifiersComposite : InputBindingComposite
    Remarks

    This composite can be used to require two buttons to be held in order to "activate" another binding. 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 control, e.g. "SHIFT+CTRL+1".

    // Create a button action that triggers when SHIFT+CTRL+1
    // is pressed on the keyboard.
    var action = new InputAction(type: InputActionType.Button);
    action.AddCompositeBinding("TwoModifiers")
        .With("Modifier", "<Keyboard>/ctrl")
        .With("Modifier", "<Keyboard>/shift")
        .With("Binding", "<Keyboard>/1")

    However, this can also be used to "gate" other types of controls. For example, a "look" action could be bound to mouse delta such that the ctrlKey and shiftKey on the keyboard have to be pressed in order for the player to be able to look around.

    var action = new InputAction();
    action.AddCompositeBinding("TwoModifiers")
        .With("Modifier1", "<Keyboard>/ctrl")
        .With("Modifier2", "<Keyboard>/shift")
        .With("Binding", "<Mouse>/delta");

    Fields

    binding

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

    Declaration
    public int binding
    Field Value
    Type Description
    int

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

    Remarks

    This property is automatically assigned by the input system.

    See Also
    OneModifierComposite

    modifier1

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

    Declaration
    public int modifier1
    Field Value
    Type Description
    int

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

    Remarks

    This property is automatically assigned by the input system.

    See Also
    OneModifierComposite

    modifier2

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

    Declaration
    public int modifier2
    Field Value
    Type Description
    int

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

    Remarks

    This property is automatically assigned by the input system.

    See Also
    OneModifierComposite

    overrideModifiersNeedToBePressedFirst

    If set to true, the built-in logic to determine if modifiers need to be pressed first is overridden. Default value is false.

    Declaration
    public bool overrideModifiersNeedToBePressedFirst
    Field Value
    Type Description
    bool
    Remarks

    By default, if binding is bound to only ButtonControls, then the composite requires both modifier1 and modifier2 to be pressed before pressing binding. This means that binding to, for example, Ctrl+Shift+B, the ctrl and shift keys have to be pressed before pressing the B key. This is the behavior usually expected with keyboard shortcuts.

    However, when binding, for example, Ctrl+Shift+MouseDelta, it should be possible to press ctrl and shift at any time and in any order. The default logic will automatically detect the difference between this binding and the button binding in the example above and behave accordingly.

    This field allows you to explicitly override this default inference and make it so that regardless of what binding is bound to, any press sequence is acceptable. For the example binding to Ctrl+Shift+B, it would mean that pressing B and only then pressing Ctrl and Shift will still trigger the binding.

    See Also
    OneModifierComposite

    Properties

    valueSizeInBytes

    Size of the largest value that may be read from the controls bound to binding.

    Declaration
    public override int valueSizeInBytes { get; }
    Property Value
    Type Description
    int
    Overrides
    InputBindingComposite.valueSizeInBytes
    See Also
    OneModifierComposite

    valueType

    Type of values read from controls bound to binding.

    Declaration
    public override Type valueType { get; }
    Property Value
    Type Description
    Type
    Overrides
    InputBindingComposite.valueType
    See Also
    OneModifierComposite

    Methods

    EvaluateMagnitude(ref InputBindingCompositeContext)

    Determine the current level of actuation of the composite.

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

    Callback context for the binding composite. Use this to access the values supplied by part bindings.

    Returns
    Type Description
    float
    Overrides
    InputBindingComposite.EvaluateMagnitude(ref InputBindingCompositeContext)
    Remarks

    This method by default returns -1, meaning that the composite does not support magnitudes. You can override the method to add support for magnitudes.

    See EvaluateMagnitude() for details of how magnitudes work.

    See Also
    EvaluateMagnitude()

    FinishSetup(ref InputBindingCompositeContext)

    Called after binding resolution for an InputActionMap is complete.

    Declaration
    protected override void FinishSetup(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context
    Overrides
    InputBindingComposite.FinishSetup(ref InputBindingCompositeContext)
    Remarks

    Some composites do not have predetermine value types. Two examples of this are OneModifierComposite and TwoModifiersComposite, which both have a "binding" part that can be bound to arbitrary controls. This means that the value type of these bindings can only be determined at runtime.

    Overriding this method allows accessing the actual controls bound to each part at runtime.

    [InputControl] public int binding;

         protected override void FinishSetup(ref InputBindingContext context)
         {
             // Get all controls bound to the 'binding' part.
             var controls = context.controls
                 .Where(x => x.part == binding)
                 .Select(x => x.control);
         }</code></pre></example>
    
    See Also
    OneModifierComposite

    ReadValue(ref InputBindingCompositeContext, void*, int)

    Read a value from the composite without having to know the value type (unlike ReadValue(ref InputBindingCompositeContext) and without allocating GC heap memory (unlike ReadValueAsObject(ref InputBindingCompositeContext)).

    Declaration
    public override void ReadValue(ref InputBindingCompositeContext context, void* buffer, int bufferSize)
    Parameters
    Type Name Description
    InputBindingCompositeContext context

    Callback context for the binding composite. Use this to access the values supplied by part bindings.

    void* buffer

    Buffer that receives the value read for the composite.

    int bufferSize

    Size of the buffer allocated at buffer.

    Overrides
    InputBindingComposite.ReadValue(ref InputBindingCompositeContext, void*, int)
    Remarks

    This API will be used if someone calls ReadValue(void*, int) with the action leading to the composite.

    By deriving from InputBindingComposite<TValue>, this will automatically be implemented for you.

    Exceptions
    Type Condition
    ArgumentException

    bufferSize is smaller than valueSizeInBytes.

    ArgumentNullException

    buffer is null.

    See Also
    ReadValue(void*, int)

    ReadValueAsObject(ref InputBindingCompositeContext)

    Read the value of the composite as a boxed object. This allows reading the value without having to know the value type and without having to deal with raw byte buffers.

    Declaration
    public override object ReadValueAsObject(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context

    Callback context for the binding composite. Use this to access the values supplied by part bindings.

    Returns
    Type Description
    object

    The current value of the composite according to the state passed in through context.

    Overrides
    InputBindingComposite.ReadValueAsObject(ref InputBindingCompositeContext)
    Remarks

    This API will be used if someone calls ReadValueAsObject() with the action leading to the composite.

    By deriving from InputBindingComposite<TValue>, this will automatically be implemented for you.

    See Also
    OneModifierComposite

    See Also

    OneModifierComposite
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)