Class ButtonWithTwoModifiers
A button with two additional modifiers. The button only triggers when both modifiers are pressed.
Inherited Members
Namespace: UnityEngine.InputSystem.Composites
Assembly: Unity.InputSystem.dll
Syntax
[DisplayStringFormat("{modifier1}+{modifier2}+{button}")]
public class ButtonWithTwoModifiers : InputBindingComposite<float>
Remarks
This composite can be used to require two other buttons to be held while using the control 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("TwoModifiers")
.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 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 |
---|---|
int | Part index to use with ReadValue<TValue>(int). |
Remarks
This property is automatically assigned by the input system.
See Also
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
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
overrideModifiersNeedToBePressedFirst
If set to true
, modifier1 and/or modifier2 can be pressed after button
and the composite will still trigger. Default is false.
Declaration
public bool overrideModifiersNeedToBePressedFirst
Field Value
Type | Description |
---|---|
bool |
Remarks
By default, modifier1 and modifier2 are required to be in pressed state before or at the same
time that button goes into pressed state for the composite as a whole to trigger. This means that binding to,
for example, Ctrl+Shift+B
, the ctrl
shift
keys have to be pressed before pressing the B
key.
This is the behavior usually expected with keyboard shortcuts.
This parameter can be used to bypass this behavior and allow any timing between modifier1, modifier2, and button. The only requirement is for all of them to concurrently be in pressed state.
See Also
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 |
---|---|
float | A >0 value if the composite is currently actuated. |
Overrides
See Also
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
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
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 |
---|---|
float | The current value of the composite. |