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 an optimized data type that can represent a control's value in memory directly.
Declaration
protected override FourCC CalculateOptimizedControlDataType()
Returns
Type | Description |
---|---|
FourCC | An optimized data type that can represent a control's value in memory directly. InputStateBlock |
Overrides
Remarks
The value then is cached in optimizedControlDataType. This method is for internal use only, you should not call this from your own code.
CompareValue(void*, void*)
Compared values in state buffers.
Declaration
public override bool CompareValue(void* firstStatePtr, void* secondStatePtr)
Parameters
Type | Name | Description |
---|---|---|
void* | firstStatePtr | The first state buffer to read value from. |
void* | secondStatePtr | The second state buffer to read value from. |
Returns
Type | Description |
---|---|
bool | True if the buffer values match. False if they differ. |
Overrides
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
Remarks
Magnitudes do not make sense for all types of controls. For example, for a control that represents an enumeration of values (such as TouchPhaseControl), there is no meaningful linear ordering of values (one could derive a linear ordering through the actual enum values but their assignment may be entirely arbitrary; it is unclear whether a state of Canceled has a higher or lower "magnitude" as a state of Began).
Controls that have no meaningful magnitude will return -1 when calling this method. Any negative return value should be considered an invalid value.
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.
Examples
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");
}
}
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*)
Read value from provided statePtr
.
Declaration
public override float ReadUnprocessedValueFromState(void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
void* | statePtr | State pointer to read from. |
Returns
Type | Description |
---|---|
float | The controls current value. |
Overrides
Remarks
Read value from provided statePtr
without any caching.
See Also
WriteValueIntoState(float, void*)
Write a value into state at the given memory.
Declaration
public override void WriteValueIntoState(float value, void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
float | value | Value for the control to store in the state. |
void* | statePtr | State containing the control's stateBlock. Will receive the state as converted from the given value. |
Overrides
Remarks
Writing values will NOT apply processors to the given value. This can mean that when reading a value from a control after it has been written to its state, the resulting value differs from what was written.
Exceptions
Type | Condition |
---|---|
NotSupportedException | The control does not support writing. This is the case, for example, that compute values (such as the magnitude of a vector). |