Skip to content

Commit df3aa91

Browse files
ducketsjamesmcgill
andauthored
DOCF-1072 restructured How Do I? page. (#1658)
* DOCF-1072 restructured most of How Do I? page. * minor docs link fixes * DOCF-3072 - add solution for how to wait for any button or key press * DOCF-3073 - How to create custom devices * xr device sample code fix and howdoi anchor link fixes * Fixed bug relating to link in H3 header * Another anchor link fix * Moved sample code for HMD extra update * whitespace formatting fixes --------- Co-authored-by: James McGill <jamesmcgill@users.noreply.github.com>
1 parent 3c10099 commit df3aa91

13 files changed

Lines changed: 479 additions & 653 deletions

File tree

Packages/com.unity.inputsystem/Documentation~/Debugging.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Debugging
22

3-
* [Input Debugger](#input-debugger)
4-
* [Debugging Devices](#debugging-devices)
5-
* [Debugging Actions](#debugging-actions)
6-
* [Debugging users and PlayerInput](#debugging-users-and-playerinput)
7-
* [Debugging layouts](#debugging-layouts)
8-
* [Debugging Remotely](#debugging-remotely)
9-
* [Device Simulator](#device-simulator)
10-
* [Unity Remote](#unity-remote)
3+
- [Debugging](#debugging)
4+
- [Input Debugger](#input-debugger)
5+
- [Debugging Devices](#debugging-devices)
6+
- [Debugging Actions](#debugging-actions)
7+
- [Debugging users and PlayerInput](#debugging-users-and-playerinput)
8+
- [Debugging layouts](#debugging-layouts)
9+
- [Debugging remotely](#debugging-remotely)
10+
- [Input visualizers](#input-visualizers)
11+
- [`InputControlVisualizer`](#inputcontrolvisualizer)
12+
- [`InputActionVisualizer`](#inputactionvisualizer)
13+
- [Device Simulator](#device-simulator)
14+
- [Unity Remote (iOS, Android)](#unity-remote)
15+
- [Other tips:](#other-tips)
1116

1217
When something isn't working as expected, the quickest way to troubleshoot what's wrong is the Input Debugger in the Unity Editor. The Input Debugger provides access to the activity of the Input System in both the Editor and the connected Players.
1318

@@ -58,7 +63,7 @@ When there are [`InputUser`](UserManagement.md) instances (if you use `PlayerInp
5863

5964
### Debugging layouts
6065

61-
The [__Layouts__](Layouts.md) list in the Input Debugger window displays a breakdown of all registered [Control and Device layouts](Layouts.md). This is the database of supported hardware and the knowledge of how to represent a given piece of input hardware. It's useful when you want to [create a new Device mapping](HowDoI.md#create-my-own-custom-devices) and see how the Input System represents it.
66+
The [__Layouts__](Layouts.md) list in the Input Debugger window displays a breakdown of all registered [Control and Device layouts](Layouts.md). This is the database of supported hardware and the knowledge of how to represent a given piece of input hardware. It's useful when you want to [create a new Device mapping](HID.md#creating-a-custom-device-layout) and see how the Input System represents it.
6267

6368
![Layouts in Input Debugger](Images/LayoutsInDebugger.png)
6469

@@ -96,16 +101,16 @@ When Device Simulator window is in use, mouse and pen inputs on the simulated de
96101

97102
To prevent conflicts between simulated touchscreen inputs and native mouse and pen inputs, Device Simulator disables all native mouse and pen devices.
98103

99-
## <a name="unity-remote"></a> Unity Remote (iOS, Android)
100-
101-
>__Note__: Joysticks/gamepads are not yet supported over the Unity Remote. No joystick/gamepad input from the mobile device will come through in the editor.
102-
103-
>__Note__: This requires Unity 2021.2.18 or later.
104+
## Unity Remote
104105

105106
The Unity Remote is an app available for iOS and Android which allows using a mobile device for input while running in the Unity Editor. You can find details about the app and how to install it in the [Unity manual](https://docs.unity3d.com/Manual/UnityRemote5.html).
106107

107108
If you would like to try out the Unity Remote app, you can [install](Installation.md#installing-samples) the "Unity Remote" sample that is provided with the Input System package.
108109

110+
>__Note__: Joysticks/gamepads are not yet supported over the Unity Remote. No joystick/gamepad input from the mobile device will come through in the editor.
111+
112+
>__Note__: This requires Unity 2021.2.18 or later.
113+
109114
When in play mode in the Editor and connected to the Unity Remote app, you will see a number of Devices have been added with the [`InputDevice.remote`](../api/UnityEngine.InputSystem.InputDevice.html#UnityEngine_InputSystem_InputDevice_remote) flag set to true:
110115

111116
- [`Touchscreen`](../api/UnityEngine.InputSystem.Touchscreen.html)
@@ -125,3 +130,44 @@ The [`Accelerometer`](../api/UnityEngine.InputSystem.Accelerometer.html) device
125130
The remaining sensors listed above will need to be explicitly enabled via [`InputSystem.EnableDevice`](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_EnableDevice_UnityEngine_InputSystem_InputDevice_) just like local sensors. Setting the sampling frequency on these sensors from the Unity Remote using [`Sensor.samplingFrequency`](../api/UnityEngine.InputSystem.Sensor.html#UnityEngine_InputSystem_Sensor_samplingFrequency) will be relayed to the device but note that setting the frequency on one of them will set it for all of them.
126131

127132
Touch coordinates from the device will be translated to the screen coordinates of the Game View inside the Editor.
133+
134+
## Other tips:
135+
136+
To record events flowing through the system, use this code:
137+
138+
```C#
139+
140+
// You can also provide a device ID to only
141+
// trace events for a specific device.
142+
var trace = new InputEventTrace();
143+
144+
trace.Enable();
145+
146+
var current = new InputEventPtr();
147+
while (trace.GetNextEvent(ref current))
148+
{
149+
Debug.Log("Got some event: " + current);
150+
}
151+
152+
// Also supports IEnumerable.
153+
foreach (var eventPtr in trace)
154+
Debug.Log("Got some event: " + eventPtr);
155+
156+
// Trace consumes unmanaged resources. Make sure you dispose it correctly to avoid memory leaks.
157+
trace.Dispose();
158+
159+
```
160+
161+
To see events as they're processed, use this code:
162+
163+
```C#
164+
165+
InputSystem.onEvent +=
166+
(eventPtr, device) =>
167+
{
168+
// Can handle events yourself, for example, and then stop them
169+
// from further processing by marking them as handled.
170+
eventPtr.handled = true;
171+
};
172+
173+
```

Packages/com.unity.inputsystem/Documentation~/Devices.md

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
# Devices
22

3-
* [Device descriptions](#device-descriptions)
4-
* [Capabilities](#capabilities)
5-
* [Matching](#matching)
6-
* [Hijacking the matching process](#hijacking-the-matching-process)
7-
* [Device lifecycle](#device-lifecycle)
8-
* [Device creation](#device-creation)
9-
* [Device removal](#device-removal)
10-
* [Device resets](#device-resets)
11-
* [Device syncs](#device-syncs)
12-
* [Device enabling and disabling](#device-enabling-and-disabling)
13-
* [Background and focus change behavior](#background-and-focus-change-behavior)
14-
* [Domain reloads](#domain-reloads-in-the-editor)
15-
* [Native Devices](#native-devices)
16-
* [Disconnected Devices](#disconnected-devices)
17-
* [Device IDs](#device-ids)
18-
* [Device usages](#device-usages)
19-
* [Device commands](#device-commands)
20-
* [Working with Devices](#working-with-devices)
21-
* [Monitoring Devices](#monitoring-devices)
22-
* [Adding and removing Devices](#adding-and-removing-devices)
23-
* [Creating custom Devices](#creating-custom-devices)
3+
- [Devices](#devices)
4+
- [Device descriptions](#device-descriptions)
5+
- [Capabilities](#capabilities)
6+
- [Matching](#matching)
7+
- [Hijacking the matching process](#hijacking-the-matching-process)
8+
- [Device lifecycle](#device-lifecycle)
9+
- [Device creation](#device-creation)
10+
- [Device removal](#device-removal)
11+
- [Device resets](#device-resets)
12+
- [Device syncs](#device-syncs)
13+
- [Device enabling and disabling](#device-enabling-and-disabling)
14+
- [Background and focus change behavior](#background-and-focus-change-behavior)
15+
- [Domain reloads in the Editor](#domain-reloads-in-the-editor)
16+
- [Native Devices](#native-devices)
17+
- [Disconnected Devices](#disconnected-devices)
18+
- [Device IDs](#device-ids)
19+
- [Device usages](#device-usages)
20+
- [Device commands](#device-commands)
21+
- [Sending commands to Devices](#sending-commands-to-devices)
22+
- [Adding custom device Commands](#adding-custom-device-commands)
23+
- [Device state](#device-state)
24+
- [State changes](#state-changes)
25+
- [Monitoring state changes](#monitoring-state-changes)
26+
- [Synthesizing state](#synthesizing-state)
27+
- [Working with Devices](#working-with-devices)
28+
- [Monitoring Devices](#monitoring-devices)
29+
- [Adding and removing Devices](#adding-and-removing-devices)
30+
- [Creating custom Devices](#creating-custom-devices)
31+
- [Step 1: The state struct](#step-1-the-state-struct)
32+
- [Step 2: The Device class](#step-2-the-device-class)
33+
- [Step 3: The Update method](#step-3-the-update-method)
34+
- [Step 4: Device registration and creation](#step-4-device-registration-and-creation)
35+
- [Step 5: `current` and `all` (optional)](#step-5-current-and-all-optional)
36+
- [Step 6: Device Commands (Optional)](#step-6-device-commands-optional)
2437

2538
Physically, Input Devices represent devices attached to the computer, which a user can use to control the app. Logically, Input Devices are the top-level container for [Controls](Controls.md). The [`InputDevice`](../api/UnityEngine.InputSystem.InputDevice.html) class is itself a specialization of [`InputControl`](../api/UnityEngine.InputSystem.InputControl.html). See [supported Devices](SupportedDevices.md) to see what kind of Devices the Input System currently supports.
2639

@@ -187,6 +200,23 @@ Devices that the [native backend](Architecture.md#native-backend) reports are co
187200

188201
The Input System remembers native Devices. For example, if the system has no matching layout when the Device is first reported, but a layout which matches the device is registered later, the system uses this layout to recreate the Device.
189202

203+
You can force the Input System to use your own [layout](Layouts.md) when the native backend discovers a specific Device, by describing the Device in the layout, like this:
204+
205+
```
206+
{
207+
"name" : "MyGamepad",
208+
"extend" : "Gamepad",
209+
"device" : {
210+
// All strings in here are regexs and case-insensitive.
211+
"product" : "MyController",
212+
"manufacturer" : "MyCompany"
213+
}
214+
}
215+
```
216+
217+
Note: You don't have to restart Unity in order for changes in your layout to take effect on native Devices. The Input System applies changes automatically on every domain reload, so you can just keep refining a layout and your Device is recreated with the most up-to-date version every time scripts are recompiled.
218+
219+
190220
### Disconnected Devices
191221

192222
If you want to get notified when Input Devices disconnect, subscribe to the [`InputSystem.onDeviceChange`](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_onDeviceChange) event, and look for events of type [`InputDeviceChange.Disconnected`](../api/UnityEngine.InputSystem.InputDeviceChange.html).
@@ -250,14 +280,22 @@ InputSystem.onDeviceChange +=
250280
switch (change)
251281
{
252282
case InputDeviceChange.Added:
253-
Debug.Log("New device added: " + device);
283+
// New Device.
284+
break;
285+
case InputDeviceChange.Disconnected:
286+
// Device got unplugged.
287+
break;
288+
case InputDeviceChange.Connected:
289+
// Plugged back in.
254290
break;
255-
256291
case InputDeviceChange.Removed:
257-
Debug.Log("Device removed: " + device);
292+
// Remove from Input System entirely; by default, Devices stay in the system once discovered.
293+
break;
294+
default:
295+
// See InputDeviceChange reference for other event types.
258296
break;
259297
}
260-
};
298+
}
261299
```
262300

263301
[`InputSystem.onDeviceChange`](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_onDeviceChange) delivers notifications for other device-related changes as well. See the [`InputDeviceChange` enum](../api/UnityEngine.InputSystem.InputDeviceChange.html) for more information.
@@ -277,7 +315,7 @@ There are two main situations in which you might need to create a custom Device:
277315
1. You have an existing API that generates input, and which you want to reflect into the Input System.
278316
2. You have an HID that the Input System ignores, or that the Input system auto-generates a layout for that doesn't work well enough for your needs.
279317

280-
For the second scenario, see [Overriding the HID Fallback](HID.md#overriding-the-hid-fallback).
318+
For the second scenario, see [Overriding the HID Fallback](HID.md#creating-a-custom-device-layout).
281319

282320
The steps below deal with the first scenario, where you want to create a new Input Device entirely from scratch and provide input to it from a third-party API.
283321

Packages/com.unity.inputsystem/Documentation~/Gamepad.md

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
# Gamepad Support
22

3-
* [Controls](#controls)
4-
* [Polling](#polling)
5-
* [Rumble](#rumble)
6-
* [Pausing, resuming, and stopping haptics](#pausing-resuming-and-stopping-haptics)
7-
* [PlayStation controllers](#playstation-controllers)
8-
* [Xbox controllers](#xbox-controllers)
9-
* [Switch controller](#switch-controllers)
10-
* [Cursor Control](#cursor-control)
3+
- [Gamepad Support](#gamepad-support)
4+
- [Controls](#controls)
5+
- [Deadzones](#deadzones)
6+
- [Polling](#polling)
7+
- [Rumble](#rumble)
8+
- [Pausing, resuming, and stopping haptics](#pausing-resuming-and-stopping-haptics)
9+
- [PlayStation controllers](#playstation-controllers)
10+
- [Xbox controllers](#xbox-controllers)
11+
- [Switch controllers](#switch-controllers)
12+
- [Cursor Control](#cursor-control)
1113

1214
A [`Gamepad`](../api/UnityEngine.InputSystem.Gamepad.html) is narrowly defined as a Device with two thumbsticks, a D-pad, and four face buttons. Additionally, gamepads usually have two shoulder and two trigger buttons. Most gamepads also have two buttons in the middle.
1315

1416
A gamepad can have additional Controls, such as a gyro, which the Device can expose. However, all gamepads are guaranteed to have at least the minimum set of Controls described above.
1517

1618
Gamepad support guarantees the correct location and functioning of Controls across platforms and hardware. For example, a PS4 DualShock controller layout should look identical regardless of which platform it is supported on. A gamepad's south face button should always be the lowermost face button.
1719

18-
>NOTE: Generic [HID](./HID.md) gamepads will __not__ be surfaced as [`Gamepad`](../api/UnityEngine.InputSystem.Gamepad.html) devices but rather be created as generic [joysticks](./Joystick.md). This is because the Input System cannot guarantee correct mapping of buttons and axes on the controller (the information is simply not available at the HID level). Only HID gamepads that are explicitly supported by the Input System (like the PS4 controller) will come out as gamepads. Note that you can set up the same kind of support for specific HID gamepads yourself (see ["Overriding the HID Fallback"](./HID.md#overriding-the-hid-fallback)).
20+
>NOTE: Generic [HID](./HID.md) gamepads will __not__ be surfaced as [`Gamepad`](../api/UnityEngine.InputSystem.Gamepad.html) devices but rather be created as generic [joysticks](./Joystick.md). This is because the Input System cannot guarantee correct mapping of buttons and axes on the controller (the information is simply not available at the HID level). Only HID gamepads that are explicitly supported by the Input System (like the PS4 controller) will come out as gamepads. Note that you can set up the same kind of support for specific HID gamepads yourself (see ["Overriding the HID Fallback"](./HID.md#creating-a-custom-device-layout)).
1921
2022
>NOTE: In case you want to use the gamepad for driving mouse input, there is a sample called `Gamepad Mouse Cursor` you can install from the package manager UI when selecting the Input System package. The sample demonstrates how to set up gamepad input to drive a virtual mouse cursor.
2123
@@ -58,6 +60,45 @@ Gamepad.current[GamepadButton.Triangle]
5860
Gamepad.current["Triangle"]
5961
```
6062

63+
### Deadzones
64+
65+
Deadzones prevent accidental input due to slight variations in where gamepad sticks come to rest at their centre point. They allow a certain small inner area where the input is considered to be zero even if it is slightly off from the zero position.
66+
67+
To add a deadzone to gamepad stick, put a [stick deadzone Processor](Processors.md#stick-deadzone) on the sticks, like this:
68+
69+
```JSON
70+
{
71+
"name" : "MyGamepad",
72+
"extend" : "Gamepad",
73+
"controls" : [
74+
{
75+
"name" : "leftStick",
76+
"processors" : "stickDeadzone(min=0.125,max=0.925)"
77+
},
78+
{
79+
"name" : "rightStick",
80+
"processors" : "stickDeadzone(min=0.125,max=0.925)"
81+
}
82+
]
83+
}
84+
```
85+
86+
You can do the same in your C# state structs.
87+
88+
```C#
89+
public struct MyDeviceState
90+
{
91+
[InputControl(processors = "stickDeadzone(min=0.125,max=0.925)"]
92+
public StickControl leftStick;
93+
[InputControl(processors = "stickDeadzone(min=0.125,max=0.925)"]
94+
public StickControl rightStick;
95+
}
96+
```
97+
98+
The gamepad layout already adds stick deadzone processors which take their min and max values from [`InputSettings.defaultDeadzoneMin`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultDeadzoneMin) and [`InputSettings.defaultDeadzoneMax`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultDeadzoneMax).
99+
100+
101+
61102
## Polling
62103

63104
On Windows (XInput controllers only), Universal Windows Platform (UWP), and Switch, Unity polls gamepads explicitly rather than deliver updates as events.

0 commit comments

Comments
 (0)