Class ButtonWithOneModifier
A button with an additional modifier. The button only triggers when the modifier is pressed.
Inherited Members
Namespace: UnityEngine .InputSystem .Composites
Assembly: Unity.InputSystem.dll
Syntax
[DisplayStringFormat("{modifier}+{button}")]
public class ButtonWithOneModifier : InputBindingComposite<float>
Remarks
This composite can be used to require another button to be held while pressing the button that triggers the action. This is most commonly used on keyboards to require one of the modifier keys (shift, ctrl, or alt) to be held in combination with another key, e.g. "CTRL+1".
// Create a button action that triggers when CTRL+1
// is pressed on the keyboard.
var action = new InputAction(type: InputActionType.Button);
action.AddCompositeBinding("ButtonWithOneModifier")
.With("Modifier", "<Keyboard>/leftCtrl")
.With("Modifier", "<Keyboard>/rightControl")
.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 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("ButtonWithOneModifier")
.With("Modifier", "<Gamepad>/buttonSouth")
.With("Button", "<Gamepad>/leftTrigger");
Fields
button
Binding for the button that is gated by the modifier. The composite will assume the value of this button while the modifier is pressed.
Declaration
public int button
Field Value
Type | Description |
---|---|
int | Part index to use with Read |
Remarks
This property is automatically assigned by the input system.
See Also
modifier
Binding for the button that acts as a modifier, e.g. <Keyboard/leftCtrl
.
Declaration
public int modifier
Field Value
Type | Description |
---|---|
int | Part index to use with Read |
Remarks
This property is automatically assigned by the input system.
See Also
modifiersOrder
If set to Ordered
or Unordered
, the built-in logic to determine if modifiers need to be pressed first is overridden.
Declaration
[Tooltip("By default it follows the Input Consumption setting to determine if the modifers keys need to be pressed first.")]
public ButtonWithOneModifier.ModifiersOrder modifiersOrder
Field Value
Type | Description |
---|---|
Button |
Remarks
By default, if the setting shortcutShift+B
,
the shift
key has to be pressed before pressing the B
key. This is the behavior usually expected with
keyboard shortcuts.
If the setting shortcut
This parameter can be used to bypass this behavior and enforce the timing order or allow any timing between modifier and button. The only requirement is for them both to concurrently be in pressed state.
See Also
Methods
EvaluateMagnitude(ref InputBindingCompositeContext)
Same as Read
Declaration
public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
Parameters
Type | Name | Description |
---|---|---|
Input |
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 Input
Declaration
protected override void FinishSetup(ref InputBindingCompositeContext context)
Parameters
Type | Name | Description |
---|---|---|
Input |
context |
Overrides
Remarks
Some composites do not have predetermine value types. Two examples of this are
One"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)
Declaration
public override float ReadValue(ref InputBindingCompositeContext context)
Parameters
Type | Name | Description |
---|---|---|
Input |
context | Evaluation context passed in from the input system. |
Returns
Type | Description |
---|---|
float | The current value of the composite. |