Class AxisComposite
A single axis value computed from one axis that pulls in the negative direction (min
Inherited Members
Namespace: UnityEngine .InputSystem .Composites
Assembly: Unity.InputSystem.dll
Syntax
[DisplayStringFormat("{negative}/{positive}")]
public class AxisComposite : InputBindingComposite<float>
Remarks
The limits of the axis are determined by min[-1..1]
. The values can be set as parameters.
var action = new InputAction();
action.AddCompositeBinding("Axis(minValue=0,maxValue=2)")
.With("Negative", "<Keyboard>/a")
.With("Positive", "<Keyboard>/d");
If both axes are actuated at the same time, the behavior depends on which
This is useful, for example, in a driving game where break should cancel out accelerate.
By binding negative to the break control(s) and positive to the
acceleration control(s), and setting which
The actual absolute values of negative and positive are used
to scale minmaxValue * 0.5
(the actual formula is midPoint + (maxValue - midPoint) * positive
).
Fields
maxValue
The upper bound that the axis is limited to. 1 by default.
Declaration
[Tooltip("Value to return when the positive side is fully actuated.")]
public float maxValue
Field Value
Type | Description |
---|---|
float |
Remarks
This value corresponds to the full actuation of the control(s) bound to positive.
var action = new InputAction();
action.AddCompositeBinding("Axis(minValue=0,maxValue=2)")
.With("Negative", "<Keyboard>/a")
.With("Positive", "<Keyboard>/d");
See Also
minValue
The lower bound that the axis is limited to. -1 by default.
Declaration
[Tooltip("Value to return when the negative side is fully actuated.")]
public float minValue
Field Value
Type | Description |
---|---|
float |
Remarks
This value corresponds to the full actuation of the control(s) bound to negative.
var action = new InputAction();
action.AddCompositeBinding("Axis(minValue=0,maxValue=2)")
.With("Negative", "<Keyboard>/a")
.With("Positive", "<Keyboard>/d");
See Also
negative
Binding for the axis input that controls the negative [min
Declaration
public int negative
Field Value
Type | Description |
---|---|
int |
Remarks
This property is automatically assigned by the input system.
positive
Binding for the axis input that controls the positive [0..max
Declaration
public int positive
Field Value
Type | Description |
---|---|
int |
Remarks
This property is automatically assigned by the input system.
whichSideWins
If both the positive and negative button are actuated, this determines which value is returned from the composite.
Declaration
[Tooltip("If both the positive and negative side are actuated, decides what value to return. 'Neither' (default) means that the resulting value is the midpoint between min and max. 'Positive' means that max will be returned. 'Negative' means that min will be returned.")]
public AxisComposite.WhichSideWins whichSideWins
Field Value
Type | Description |
---|---|
Axis |
Properties
midPoint
The value that is returned if the composite is in a neutral position, that is, if
neither positive nor negative are actuated or if
which
Declaration
public float midPoint { get; }
Property Value
Type | Description |
---|---|
float |
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 |
---|---|---|
Input |
context | Callback context for the binding composite. Use this to access the values supplied by part bindings. |
Returns
Type | Description |
---|---|
float |
Overrides
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 Evaluate
See Also
ReadValue(ref InputBindingCompositeContext)
Read a value for the composite given the supplied context.
Declaration
public override float ReadValue(ref InputBindingCompositeContext context)
Parameters
Type | Name | Description |
---|---|---|
Input |
context | Callback context for the binding composite. Use this to access the values supplied by part bindings. |
Returns
Type | Description |
---|---|
float | The current value of the composite according to the state made
accessible through |
Overrides
Remarks
This is the main method to implement in custom composites.
public class CustomComposite : InputBindingComposite<float>
{
[InputControl(layout = "Button")]
public int button;
public float scaleFactor = 1;
public override float ReadValue(ref InputBindingComposite context)
{
return context.ReadValue<float>(button) * scaleFactor;
}
}</code></pre></example>
The other method to consider overriding is Evaluate