Class OneModifierComposite
A binding with an additional modifier. The bound controls only trigger when the modifier is pressed.
Inherited Members
Namespace: UnityEngine.InputSystem.Composites
Syntax
public class OneModifierComposite : InputBindingComposite
Remarks
This composite can be used to require a button to be held in order to "activate" another binding. 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 control, 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("OneModifier")
.With("Modifier", "<Keyboard>/ctrl")
.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 altKey on the keyboard has to be pressed in order for the player to be able to look around.
lookAction.AddCompositeBinding("OneModifier")
.With("Modifier", "<Keyboard>/alt")
.With("Binding", "<Mouse>/delta")
Fields
binding
Binding for the control that is gated by the modifier. The composite will assume the value of this control while the modifier is considered pressed (that is, has a magnitude equal to or greater than the button press point).
Declaration
public int binding
Field Value
Type | Description |
---|---|
Int32 | Part index to use with ReadValue<TValue>(Int32). |
Remarks
This property is automatically assigned by the input system.
modifier
Binding for the button that acts as a modifier, e.g. <Keyboard/ctrl
.
Declaration
public int modifier
Field Value
Type | Description |
---|---|
Int32 | Part index to use with ReadValue<TValue>(Int32). |
Remarks
This property is automatically assigned by the input system.
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 |
---|---|
Int32 |
Overrides
valueType
Type of values read from controls bound to binding.
Declaration
public override Type valueType { get; }
Property Value
Type | Description |
---|---|
Type |
Overrides
Methods
EvaluateMagnitude(ref InputBindingCompositeContext)
Declaration
public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
Parameters
Type | Name | Description |
---|---|---|
InputBindingCompositeContext | context |
Returns
Type | Description |
---|---|
Single |
Overrides
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);
}
ReadValue(ref InputBindingCompositeContext, Void*, Int32)
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. |
Int32 | bufferSize | Size of the buffer allocated at |
Overrides
Remarks
This API will be used if someone calls ReadValue(Void*, Int32) with the action leading to the composite.
By deriving from InputBindingComposite<TValue>, this will automatically be implemented for you.
See Also
ReadValueAsObject(ref InputBindingCompositeContext)
Declaration
public override object ReadValueAsObject(ref InputBindingCompositeContext context)
Parameters
Type | Name | Description |
---|---|---|
InputBindingCompositeContext | context |
Returns
Type | Description |
---|---|
Object |