Class Joystick
A joystick with an arbitrary number of buttons and axes.
Inherited Members
Namespace: UnityEngine.InputSystem
Syntax
[Preserve]
public class Joystick : InputDevice
Remarks
Joysticks are somewhat hard to classify as there is little commonality other than that there is one main stick 2D control and at least one button. From the input system perspective, everything that is not a Gamepad and that has at least one stick and one trigger control is considered a candidate for being a joystick.
Optionally, a joystick may also have the ability to twist, i.e. for the stick to rotate around its own axis, and at least one hatswitch.
Note that devices based on Joystick may have many more controls. Joystick itself only defines a minimum required to separate joysticks as a concept from other types of devices.
Properties
all
A list of joysticks currently connected to the system.
Declaration
public static ReadOnlyArray<Joystick> all { get; }
Property Value
Type | Description |
---|---|
ReadOnlyArray<Joystick> | All currently connected joystick. |
Remarks
Does not cause GC allocation.
Do not hold on to the value returned by this getter but rather query it whenever you need it. Whenever the joystick setup changes, the value returned by this getter is invalidated.
See Also
current
The joystick that was added or used last. Null if there is none.
Declaration
public static Joystick current { get; }
Property Value
Type | Description |
---|---|
Joystick | Joystick that was added or used last. |
Remarks
See MakeCurrent() for details about when a device is made current.
See Also
hatswitch
An optional control representing a four-way "hat switch" on the
joystick. If not supported, will be null
.
Declaration
public Vector2Control hatswitch { get; }
Property Value
Type | Description |
---|---|
Vector2Control | Control representing a hatswitch on the joystick. |
Remarks
Hat switches are usually thumb-operated four-way switches that operate much like the "d-pad" on a gamepad (see dpad). If present, this is the Vector2Control type control on the joystick that has the Hatswitch usage.
stick
The 2D axis of the stick itself.
Declaration
public StickControl stick { get; }
Property Value
Type | Description |
---|---|
StickControl | Control representing the main joystick axis. |
Remarks
This is the StickControl type control on the joystick that has the Primary2DMotion usage.
trigger
The primary trigger button of the joystick.
Declaration
public ButtonControl trigger { get; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the primary trigger button. |
Remarks
This is the ButtonControl type control on the joystick that has the PrimaryTrigger usage.
twist
An optional control representing the rotation of the stick around its
own axis (i.e. side-to-side circular motion). If not supported, will be
null
.
Declaration
public AxisControl twist { get; }
Property Value
Type | Description |
---|---|
AxisControl | Control representing the twist motion of the joystick. |
Remarks
This is the AxisControl type control on the joystick that has the Twist usage.
Methods
FinishSetup()
Called when the joystick has been created but before it is added to the system.
Declaration
protected override void FinishSetup()
Overrides
MakeCurrent()
Make the joystick the current one.
Declaration
public override void MakeCurrent()
Overrides
Remarks
This is called automatically by the input system when a device receives input or is added to the system. See MakeCurrent() for details.
OnAdded()
Called when the joystick is added to the system.
Declaration
protected override void OnAdded()
Overrides
OnRemoved()
Called when the joystick is removed from the system.
Declaration
protected override void OnRemoved()