Class DiscreteButtonControl
A button that is considered pressed if the underlying state has a value in the specific range.
Inheritance
Inherited Members
Namespace: UnityEngine.InputSystem.Controls
Syntax
public class DiscreteButtonControl : ButtonControl
Remarks
This control is most useful for handling HID-style hat switches. Unlike DpadControl, which by default is stored as a bitfield of four bits that each represent a direction on the pad, these hat switches enumerate the possible directions that the switch can be moved in. For example, the value 1 could indicate that the switch is moved to the left whereas 3 could indicate it is moved up.
[StructLayout(LayoutKind.Explicit, Size = 32)]
internal struct DualShock4HIDInputReport : IInputStateTypeInfo
{
[FieldOffset(0)] public byte reportId;
[InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
[InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3,maxValue=5", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5, maxValue=7", bit = 0, sizeInBits = 4)]
[FieldOffset(5)] public byte buttons1;
}
Fields
maxValue
Value (inclusive) beyond which to stop considering the button to be pressed.
Declaration
public int maxValue
Field Value
Type | Description |
---|---|
Int32 |
minValue
Value (inclusive) at which to start considering the button to be pressed.
Declaration
public int minValue
Field Value
Type | Description |
---|---|
Int32 |
Remarks
minValue is allowed to be larger than maxValue. This indicates a setup where the value wraps around beyond minValue, skips nullValue, and then goes all the way up to maxValue.
For example, if the underlying state represents a circular D-pad and enumerates its 9 possible positions (including null state) going clock-wise from 0 to 8 and with 1 indicating that the D-pad is pressed to the left, then 1, 2, and 8 would indicate that the "left" button is held on the D-pad. To set this up, set minValue to 8, maxValue to 2, and nullValue to 0 (the default).
nullValue
Value at which the button is considered to not be pressed. Usually zero. Some devices, however, use non-zero default states.
Declaration
public int nullValue
Field Value
Type | Description |
---|---|
Int32 |
wrapAtValue
Value (inclusive) at which the values cut off and wrap back around. Considered to not be set if equal to nullValue.
Declaration
public int wrapAtValue
Field Value
Type | Description |
---|---|
Int32 |
Remarks
This is useful if, for example, an enumeration has more bits than are used for "on" states of controls. For example, a bitfield of 4 bits where values 1-7 (i.e. 0001 to 0111) indicate "on" states of controls and value 8 indicating an "off" state. In that case, set nullValue to 8 and wrapAtValue to 7.
writeMode
Determines the behavior of WriteValueIntoState(Single, Void*). By default, attempting to write a DiscreteButtonControl
will result in a NotSupportedException
.
Declaration
public DiscreteButtonControl.WriteMode writeMode
Field Value
Type | Description |
---|---|
DiscreteButtonControl.WriteMode |
Methods
FinishSetup()
Declaration
protected override void FinishSetup()
Overrides
ReadUnprocessedValueFromState(Void*)
Declaration
public override float ReadUnprocessedValueFromState(void *statePtr)
Parameters
Type | Name | Description |
---|---|---|
Void* | statePtr |
Returns
Type | Description |
---|---|
Single |
Overrides
WriteValueIntoState(Single, Void*)
Declaration
public override void WriteValueIntoState(float value, void *statePtr)
Parameters
Type | Name | Description |
---|---|---|
Single | value | |
Void* | statePtr |