Class AxisControl
A floating-point axis control.
Inherited Members
Namespace: UnityEngine.InputSystem.Controls
Assembly: Unity.InputSystem.dll
Syntax
public class AxisControl : InputControl<float>
Remarks
Can optionally be configured to perform normalization. Stored as either a float, a short, a byte, or a single bit.
Constructors
AxisControl()
Default-initialize the control.
Declaration
public AxisControl()
Remarks
Defaults the format to FormatFloat.
Fields
clamp
Clamping behavior when reading values. None by default.
Declaration
public AxisControl.Clamp clamp
Field Value
Type | Description |
---|---|
AxisControl.Clamp | Clamping behavior. |
Remarks
When a value is read from the control's state, it is first converted to a floating-point number.
See Also
clampConstant
When clamp is set to ToConstantBeforeNormalize and the value is outside of the range defined by clampMin and clampMax, this value is returned.
Declaration
public float clampConstant
Field Value
Type | Description |
---|---|
float | Constant value to return when value is outside of clamping range. |
clampMax
Declaration
public float clampMax
Field Value
Type | Description |
---|---|
float | Upper bound of clamping range. Inclusive. |
clampMin
Declaration
public float clampMin
Field Value
Type | Description |
---|---|
float | Lower bound of clamping range. Inclusive. |
invert
If true, the input value will be inverted, i.e. multiplied by -1. Off by default.
Declaration
public bool invert
Field Value
Type | Description |
---|---|
bool | Whether to invert the input value. |
normalize
If true, normalize the input value to [0..1] or [-1..1] (depending on the value of normalizeZero. Off by default.
Declaration
public bool normalize
Field Value
Type | Description |
---|---|
bool | Whether to normalize input values or not. |
See Also
normalizeMax
If normalize is on, this is the input value that corresponds to 1 of the normalized [0..1] or [-1..1] range.
Declaration
public float normalizeMax
Field Value
Type | Description |
---|---|
float | Input value that should become 1. |
Remarks
In other words, with normalize on, input values are mapped from the range of [normalizeMin..normalizeMax] to [0..1] or [-1..1] (depending on normalizeZero).
normalizeMin
If normalize is on, this is the input value that corresponds to 0 of the normalized [0..1] or [-1..1] range.
Declaration
public float normalizeMin
Field Value
Type | Description |
---|---|
float | Input value that should become 0 or -1. |
Remarks
In other words, with normalize on, input values are mapped from the range of [normalizeMin..normalizeMax] to [0..1] or [-1..1] (depending on normalizeZero).
normalizeZero
Where to put the zero point of the normalization range. Only relevant if normalize is set to true. Defaults to 0.
Declaration
public float normalizeZero
Field Value
Type | Description |
---|---|
float | Zero point of normalization range. |
Remarks
The value of this property determines where the zero point is located in the range established by normalizeMin and normalizeMax.
If normalizeZero
is placed at normalizeMin, the normalization
returns a value in the [0..1] range mapped from the input value range of
normalizeMin and normalizeMax.
If normalizeZero
is placed in-between normalizeMin and
normalizeMax, normalization returns a value in the [-1..1] mapped
from the input value range of normalizeMin and normalizeMax
and the zero point between the two established by normalizeZero
.
scale
Whether the scale the input value by scaleFactor. Off by default.
Declaration
public bool scale
Field Value
Type | Description |
---|---|
bool | True if inputs should be scaled by scaleFactor. |
scaleFactor
Value to multiple input values with. Only applied if scale is true
.
Declaration
public float scaleFactor
Field Value
Type | Description |
---|---|
float | Multiplier for input values. |
Methods
CalculateOptimizedControlDataType()
Calculates and returns a optimized data type that can represent a control's value in memory directly. The value then is cached in optimizedControlDataType. This method is for internal use only, you should not call this from your own code.
Declaration
protected override FourCC CalculateOptimizedControlDataType()
Returns
Type | Description |
---|---|
FourCC |
Overrides
CompareValue(void*, void*)
Compare the value of the control as read from firstStatePtr
to that read from
secondStatePtr
and return true if they are equal.
Declaration
public override bool CompareValue(void* firstStatePtr, void* secondStatePtr)
Parameters
Type | Name | Description |
---|---|---|
void* | firstStatePtr | Memory containing the control's stateBlock. |
void* | secondStatePtr | Memory containing the control's stateBlock |
Returns
Type | Description |
---|---|
bool | True if the value of the control is equal in both |
Overrides
Remarks
Unlike CompareValue(void*, void*), this method will have to do more than just compare the memory for the control in the two state buffers. It will have to read out state for the control and run the full processing machinery for the control to turn the state into a final, processed value. CompareValue is thus more costly than CompareValue(void*, void*).
This method will apply epsilons (Epsilon) when comparing floats.
See Also
EvaluateMagnitude(void*)
Compute an absolute, normalized magnitude value that indicates the extent to which the control is actuated in the given state.
Declaration
public override float EvaluateMagnitude(void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
void* | statePtr | State containing the control's stateBlock. |
Returns
Type | Description |
---|---|
float | Amount of actuation of the control or -1 if it cannot be determined. |
Overrides
See Also
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}</code></pre></example>
Preprocess(float)
Apply modifications to the given value according to the parameters configured on the control (clamp, normalize, etc).
Declaration
protected float Preprocess(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | Input value. |
Returns
Type | Description |
---|---|
float | A processed value (clamped, normalized, etc). |
See Also
ReadUnprocessedValueFromState(void*)
Declaration
public override float ReadUnprocessedValueFromState(void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
void* | statePtr |
Returns
Type | Description |
---|---|
float |
Overrides
WriteValueIntoState(float, void*)
Declaration
public override void WriteValueIntoState(float value, void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
float | value | |
void* | statePtr |