Struct GamepadState
Default state layout for gamepads.
Implements
Namespace: UnityEngine .InputSystem .LowLevel
Assembly: Unity.InputSystem.dll
Syntax
public struct GamepadState : IInputStateTypeInfo
Remarks
Be aware that unlike some other devices such as Mouse or Touchscreen,
gamepad devices tend to have wildly varying state formats, i.e. forms in which they internally
store their input data. In practice, even on the same platform gamepads will often store
their data in different formats. This means that Gamepad
If your gamepad data is arriving in a different format, you should extend the "Gamepad" layout and customize its Controls.
A real-world example of this is the Xbox Controller on macOS, which is supported through HID. Its layout looks like this:
{
"name" : "XboxGamepadOSX",
"extend" : "Gamepad",
"format" : "HID",
"device" : { "interface" : "HID", "product" : "Xbox.*Controller" },
"controls" : [
{ "name" : "leftShoulder", "offset" : 2, "bit" : 8 },
{ "name" : "rightShoulder", "offset" : 2, "bit" : 9 },
{ "name" : "leftStickPress", "offset" : 2, "bit" : 14 },
{ "name" : "rightStickPress", "offset" : 2, "bit" : 15 },
{ "name" : "buttonSouth", "offset" : 2, "bit" : 12 },
{ "name" : "buttonEast", "offset" : 2, "bit" : 13 },
{ "name" : "buttonWest", "offset" : 2, "bit" : 14 },
{ "name" : "buttonNorth", "offset" : 2, "bit" : 15 },
{ "name" : "dpad", "offset" : 2 },
{ "name" : "dpad/up", "offset" : 0, "bit" : 8 },
{ "name" : "dpad/down", "offset" : 0, "bit" : 9 },
{ "name" : "dpad/left", "offset" : 0, "bit" : 10 },
{ "name" : "dpad/right", "offset" : 0, "bit" : 11 },
{ "name" : "start", "offset" : 2, "bit" : 4 },
{ "name" : "select", "offset" : 2, "bit" : 5 },
{ "name" : "xbox", "offset" : 2, "bit" : 2, "layout" : "Button" },
{ "name" : "leftTrigger", "offset" : 4, "format" : "BYTE" },
{ "name" : "rightTrigger", "offset" : 5, "format" : "BYTE" },
{ "name" : "leftStick", "offset" : 6, "format" : "VC2S" },
{ "name" : "leftStick/x", "offset" : 0, "format" : "SHRT", "parameters" : "normalize,normalizeMin=-0.5,normalizeMax=0.5" },
{ "name" : "leftStick/y", "offset" : 2, "format" : "SHRT", "parameters" : "invert,normalize,normalizeMin=-0.5,normalizeMax=0.5" },
{ "name" : "rightStick", "offset" : 10, "format" : "VC2S" },
{ "name" : "rightStick/x", "offset" : 0, "format" : "SHRT", "parameters" : "normalize,normalizeMin=-0.5,normalizeMax=0.5" },
{ "name" : "rightStick/y", "offset" : 2, "format" : "SHRT", "parameters" : "invert,normalize,normalizeMin=-0.5,normalizeMax=0.5" }
]
}
The same principle applies if some buttons on your Device are swapped, for example. In this case, you can remap their offsets.
Constructors
GamepadState(params GamepadButton[])
Create a gamepad state with the given buttons being pressed.
Declaration
public GamepadState(params GamepadButton[] buttons)
Parameters
Type | Name | Description |
---|---|---|
Gamepad |
buttons | Buttons to put into pressed state. |
Exceptions
Type | Condition |
---|---|
Argument |
|
See Also
Fields
buttons
Button bit mask.
Declaration
public uint buttons
Field Value
Type | Description |
---|---|
uint |
See Also
leftStick
A 2D vector representing the current position of the left stick on a gamepad.
Declaration
public Vector2 leftStick
Field Value
Type | Description |
---|---|
Vector2 |
Remarks
Each axis of the 2D vector's range goes from -1 to 1. 0 represents the stick in its center position, and -1 or 1 represents the the stick pushed to its extent in each direction along the axis.
See Also
leftTrigger
The current position of the left trigger on a gamepad.
Declaration
public float leftTrigger
Field Value
Type | Description |
---|---|
float |
Remarks
The value's range goes from 0 to 1. 0 represents the trigger in its neutral position. 1 represents the trigger in its fully pressed position.
See Also
rightStick
A 2D vector representing the current position of the right stick on a gamepad.
Declaration
public Vector2 rightStick
Field Value
Type | Description |
---|---|
Vector2 |
Remarks
Each axis of the 2D vector's range goes from -1 to 1. 0 represents the stick in its center position. -1 or 1 represents the stick pushed to its extent in each direction along the axis.
See Also
rightTrigger
The current position of the right trigger on a gamepad.
Declaration
public float rightTrigger
Field Value
Type | Description |
---|---|
float |
Remarks
The value's range goes from 0 to 1. 0 represents the trigger in its neutral position. 1 represents the trigger in its fully pressed position.
See Also
Properties
Format
Declaration
public static FourCC Format { get; }
Property Value
Type | Description |
---|---|
Four |
See Also
format
State format tag for GamepadState.
Declaration
public FourCC format { get; }
Property Value
Type | Description |
---|---|
Four |
Remarks
Holds the format tag for GamepadState ("GPAD")
See Also
Methods
WithButton(GamepadButton, bool)
Set the specific buttons to be pressed or unpressed.
Declaration
public GamepadState WithButton(GamepadButton button, bool value = true)
Parameters
Type | Name | Description |
---|---|---|
Gamepad |
button | A gamepad button. |
bool | value | Whether to set |
Returns
Type | Description |
---|---|
Gamepad |
GamepadState with a modified buttons mask. |