Skip to content

Commit 7e4b564

Browse files
authored
FIX: Architecture Docs (#800)
1 parent d4dcb3a commit 7e4b564

32 files changed

+1047
-460
lines changed

Assets/Demo/DemoPlayerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void OnMenu(InputAction.CallbackContext context)
317317
{
318318
// Leave menu.
319319

320-
user.ResumeHaptics();
320+
//user.ResumeHaptics();
321321

322322
controls.gameplay.Enable();
323323
controls.menu.Disable();///REVIEW: this should likely be left to the UI input module
@@ -328,7 +328,7 @@ public void OnMenu(InputAction.CallbackContext context)
328328
{
329329
// Enter menu.
330330

331-
user.PauseHaptics();
331+
//user.PauseHaptics();
332332

333333
controls.gameplay.Disable();
334334
controls.menu.Enable();///REVIEW: this should likely be left to the UI input module
Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
////TODO: make how we refer to these assets consistent across the docs
2-
31
# Input Action Assets
42

5-
* [Creating action assets](#creating-action-assets)
6-
* [Editing action assets](#editing-action-assets)
7-
* [Using action assets](#using-action-assets)
3+
* [Creating action assets](#creating-input-action-assets)
4+
* [Editing action assets](#editing-input-action-assets)
5+
* [Using action assets](#using-input-action-assets)
86

9-
An "action asset" is an asset containing [input actions](Actions.md) as well as their associated [bindings](ActionBindings.md) and [control schemes](ActionBindings.md#control-schemes). These assets are distinguished by the `.inputactions` file extension and are stored in a plain JSON format.
7+
An "input action asset" is an asset containing [input actions](Actions.md) as well as their associated [bindings](ActionBindings.md) and [control schemes](ActionBindings.md#control-schemes). These assets are distinguished by the `.inputactions` file extension and are stored in a plain JSON format.
108

11-
## Creating Action Assets
9+
## Creating Input Action Assets
1210

1311
To create an asset containing [input actions](Actions.md) in Unity, right-click in the Project window or open the `Assets` entry in Unity's main menu. From there, select `Create >> Input Actions`.
1412

1513
![Create Input Actions](Images/CreateInputActions.png)
1614

17-
## Editing Action Assets
15+
## Editing Input Action Assets
1816

19-
To bring up the action editor, double-click an `.inputactions` asset in the Project Browser click the "Edit asset" button in the inspector for the asset. Multiple action editor windows can be open concurrently (not on the same asset, though).
17+
To bring up the action editor, double-click an `.inputactions` asset in the Project Browser or click the "Edit asset" button in the inspector for the asset. Multiple action editor windows can be open concurrently (not on the same asset, though).
2018

2119
![Action Editor Window](Images/MyGameActions.png)
2220

2321
The action editor comes up as a separate window which can optionally be docked into Unity's main UI.
2422

2523
>NOTE: For details about how action maps, actions, and bindings work, see the documentation on [actions](Actions.md).
2624
27-
Edits made in the action asset window are not saved automatically with the project by default. To save your changes, click `Save Asset` in the window's toolbar. To discard your changes, close the window and choose "Don't Save". Alternatively, auto-saving can be toggled on by ticking the "Auto-Save" checkbox in the toolbar. This will cause any change to the asset to automatically be persisted back to disk. This setting will take effect for all `.inputactions` assets and will persist across editor sessions.
25+
Edits made in the action asset window are not saved automatically with the project by default. To save your changes, click `Save Asset` in the window's toolbar. To discard your changes, close the window and choose `Don't Save`. Alternatively, auto-saving can be toggled on by ticking the `Auto-Save` checkbox in the toolbar. This will cause any change to the asset to automatically be persisted back to disk. This setting will take effect for all `.inputactions` assets and will persist across editor sessions.
2826

2927
The editor window is divided into three panes.
3028

@@ -34,10 +32,15 @@ The editor window is divided into three panes.
3432

3533
Multiple shorts are available to provide quick access to certain common operations.
3634

37-
|Shortcut|Description|
38-
|--------|-----------|
39-
40-
35+
|Shortcut (Mac)|Shortcut (Windows)|Description|
36+
|--------------|------------------|-----------|
37+
|⌘X, ⌘C, ⌘V|Ctrl-X, Ctrl-C, Ctrl-V|Cut, Copy and Paste. Can be used on actions, action maps and binding.|
38+
|⌘D|Ctrl-D|Duplicate. Can be used on actions, action maps and bindings.|
39+
|⌘⌫|Del|Delete. Can be used on actions, action maps and bindings.|
40+
|⌥S|Alt-S|Save.|
41+
|⌥M|Alt-M|Add Action Map.|
42+
|⌥A|Alt-A|Add Action.|
43+
|⌥B|Alt-B|Add Binding.|
4144

4245

4346
>Pro Tip: You can search quickly by devices and/or control schemes directly from the search box. "d:gamepad" filters for bindings to gamepad devices whereas "g:gamepad" filters for bindings in the gamepad control scheme. Matching is case-insensitive and will match any partial name.
@@ -50,42 +53,71 @@ Multiple shorts are available to provide quick access to certain common operatio
5053
5154
* To add a new action map, click the plus icon in the header of the action map column.
5255
* To rename an existing map, either long-click the name or right-click the action map and select "Rename" from the context menu.
53-
* To delete an existing map, either right-click it and select "Delete" from the context menu or use the `Delete` key (Windows) / `Cmd-Backspace` (Mac).
54-
* To duplicate an existing map, either right-click it and select "Duplicate" or use `Ctrl-D` (Windows) / `Cmd-D` (Mac).
56+
* To delete an existing map, either right-click it and select "Delete" from the context menu or use the Delete key (Windows) / ⌘⌫ (Mac).
57+
* To duplicate an existing map, either right-click it and select "Duplicate" or use Ctrl-D (Windows) / ⌘D (Mac).
5558

5659
### Editing Actions
5760

5861
![Action Column](Images/ActionColumn.png)
5962

63+
* To add a new action, click the plus icon in the header of the action column.
64+
* To rename an existing action, either long-click the name or right-click the action map and select "Rename" from the context menu.
65+
* To delete an existing action, either right-click it and select "Delete" from the context menu or use the Delete key (Windows) / ⌘⌫ (Mac).
66+
* To duplicate an existing action, either right-click it and select "Duplicate" or use Ctrl-D (Windows) / ⌘D (Mac).
67+
68+
If you select an action you can edit it's properties in the right hand pane of the window:
6069

6170
![Action Properties](Images/ActionProperties.png)
6271

6372
### Editing Bindings
6473

74+
* To add a new binding, click the plus icon on the action you want to add it to, and select the binding type fron the popup menu.
75+
* To delete an existing binding, either right-click it and select "Delete" from the context menu or use the Delete key (Windows) / ⌘⌫ (Mac).
76+
* To duplicate an existing binding, either right-click it and select "Duplicate" or use Ctrl-D (Windows) / ⌘D (Mac).
77+
78+
If you select an action you can edit it's properties in the right hand pane of the window:
79+
6580
![Binding Properties](Images/BindingProperties.png)
6681

6782
#### Picking Controls
6883

84+
The most important property of any binding is the [control path](Controls.md#control-paths) it is bound to. To edit it, click on the popup button for the `Path` property. This will pop up a Control Picker window.
85+
6986
![Control Picker](Images/InputControlPicker.png)
7087

88+
In the control picker window, you can explore a tree of input devices and controls known to the input system to bind to. This list will be filtered by the action's [`Control Type`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_expectedControlType) property, so if the control type is `Vector2`, you will only be able to select any control which generates two-dimensional values (like a stick). The device and control tree is organized hierarchically from generic to specific. So, you can for instance navigate to "Gamepad", and choose the control path `<Gamepad>/buttonSouth`. This will then match the lower action button on any gamepad. But you can also navigate to "Gamepad", and from there scroll down to "More specific Gamepads" and select "PS4 Controller", and then choose the control path `<DualShockGamepad>/buttonSouth`. This will then only match the "cross" button on PlayStation gamepads, and not match any other gamepads.
89+
90+
Instead of browsing the tree to find the control you want, it is often easier to simply let the input system listen for input. To do that, click the "Listen" button. The list of controls will first be empty. Now you can start clicking buttons or actuating controls on the devices you want to bind to. The control picker window will list any bindings which would match the controls you pressed, and you can click on one to choose it.
91+
92+
Finally, you can choose to manually edit the binding path, instead of using the control picker. To do that, you can click the "T" button next to the control path popup. This will switch the popup to a text field, where you can enter any binding string. The advantage of doing this is that you are allowed to use wildcard (`*`) characters in your bindings. So you can for instance use a binding path such as `<Touchscreen>/touch*/press` to bind to any finger being pressed on the touchscreen (instead of manually binding to `<Touchscreen>/touch0/press`, `<Touchscreen>/touch1/press`, etc..).
93+
7194
#### Editing Composite Bindings
7295

96+
Composite bindings are bindings consisting of multiple parts, which form a control together. For instance a [2D Vector composite](ActionBindings.md#2d-vector) uses four buttons (left, right, up, down) to simulate a 2D stick input. You can learn more about how composites works and which types of composites there are [here](ActionBindings.md#composite-bindings).
97+
98+
To create a composite binding in the input action asset editor window, click the plus icon on the action you want to add it to, and select the composite binding type fron the popup menu. This will create multiple bindings entries for the action - one for the composite as a whole, and then, one level below that, one for each composite part. The composite itself does not have a binding path property, but it's individual parts do - and those can be edited like any other binding. Once you have bound all the composite's parts, the composite can work together as if you bound a single control to the action.
99+
73100
### Editing Control Schemes
74101

102+
Input Action Assets can have multiple [control schemes](ActionBindings.md#control-schemes) which let you enable or disable different sets of bindings for your actions for different types of devices.
103+
75104
![Control Scheme Properties](Images/ControlSchemeProperties.png)
76105

77-
## Using Action Assets
106+
To see the control schemes in the input action asset editor window, click the control scheme popup button in the top left of the window. This popup menu lets you add or remove control schemes to your asset. If your asset contains any control schemes, you can select a control scheme, and then the window will only show bindings belong to that scheme. If you select a binding, you will now be able to pick the control schemes for which this binding should be active in the properties view to the left of the window. When you add a new control scheme (or select an existing control scheme, and then select "Edit Control Scheme…" from the popup), a little window will open which lets you edit the name of the control scheme and which devices the scheme should be active for.
107+
108+
## Using Input Action Assets
78109

79110
### Auto-Generating Script Code for Actions
80111

81112
One of the most convenient ways to work with `.inputactions` assets in script is to generate a C# wrapper class for them automatically. This obviates the need for manually looking up actions and maps using their names and also provides easier ways for setting up callbacks.
82113

83114
To enable this, tick the `Generate C# Class` in the importer properties in the inspector of the `.inputactions` asset when selected in Unity and hit "Apply".
84115

85-
////TODO: Update screenshot
86116
![MyPlayerControls Importer Settings](Images/FireActionInputAssetInspector.png)
87117

88-
This will generate a C# script that makes working with the asset a lot simpler. TODO
118+
(You can optionally choose a path name, and a class name and namespace for the generated script, or you can keep the defaults.)
119+
120+
This will generate a C# script that makes working with the asset a lot simpler.
89121

90122
```CSharp
91123
using UnityEngine;
@@ -98,19 +130,19 @@ using UnityEngine.Experimental.Input;
98130
public class MyPlayerScript : MonoBehaviour, IGameplayActions
99131
{
100132
// MyPlayerControls is the C# class that has been generated for us.
101-
// It wraps around a reference to the .inputactions asset we created
133+
// It encapsulates the data from the .inputactions asset we created
102134
// and automatically looks up all the maps and actions for us.
103-
public MyPlayerControls controls;
104-
105-
public void Awake()
106-
{
107-
// Tell the "gameplay" action map that we want to get told about
108-
// when actions get triggered.
109-
controls.gameplay.SetCallbacks(this);
110-
}
135+
MyPlayerControls controls;
111136

112137
public void OnEnable()
113138
{
139+
if (controls == null)
140+
{
141+
controls = new MyPlayerControls();
142+
// Tell the "gameplay" action map that we want to get told about
143+
// when actions get triggered.
144+
controls.gameplay.SetCallbacks(this);
145+
}
114146
controls.gameplay.Enable();
115147
}
116148

@@ -134,4 +166,6 @@ public class MyPlayerScript : MonoBehaviour, IGameplayActions
134166

135167
### Using Action Assets with `PlayerInput`
136168

137-
### Loading Action Assets
169+
The [`PlayerInput` component](Components.md#playerinput-component) provides a convenient way to handle input for one or multiple players. It requires you to set up all your actions in an Input Action Asset, which you can then assign to the [`PlayerInput`](Components.md#playerinput-component) component. [`PlayerInput`](Components.md#playerinput-component) can then automatically handle activating action maps and selecting control schemes for you. Check the docs on [GameObject Components for Input](Components.md) to learn mode.
170+
171+
![PlayerInput](Images/PlayerInput.png)

0 commit comments

Comments
 (0)