Skip to content

Commit b7ec060

Browse files
siobhan-unitysiobhan-gibsonjo-unity
authored
DOCF-6396 - Processor content model re-org (#2123)
Co-authored-by: Siobhan <[email protected]> Co-authored-by: Jo Dawes <[email protected]>
1 parent 2f38651 commit b7ec060

12 files changed

+161
-229
lines changed

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

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,12 @@ uid: input-system-processors
33
---
44
# Processors
55

6-
An Input Processor takes a value and returns a processed result for it. The received value and result value must be of the same type. For example, you can use a [clamp](#clamp) Processor to clamp values from a control to a certain range.
7-
8-
>__Note__: To convert received input values into different types, see [composite Bindings](ActionBindings.md#composite-bindings).
9-
10-
* [Using Processors](#using-processors)
11-
* [Processors on Bindings](#processors-on-bindings)
12-
* [Processors on Actions](#processors-on-actions)
13-
* [Processors on Controls](#processors-on-controls)
14-
* [Predefined Processors](#predefined-processors)
15-
* [Clamp](#clamp)
16-
* [Invert](#invert)
17-
* [Invert Vector 2](#invert-vector-2)
18-
* [Invert Vector 3](#invert-vector-3)
19-
* [Normalize](#normalize)
20-
* [Normalize Vector 2](#normalize-vector-2)
21-
* [Normalize Vector 3](#normalize-vector-3)
22-
* [Scale](#scale)
23-
* [Scale Vector 2](#scale-vector-2)
24-
* [Scale Vector 3](#scale-vector-3)
25-
* [Axis deadzone](#axis-deadzone)
26-
* [Stick deadzone](#stick-deadzone)
27-
* [Writing custom Processors](#writing-custom-processors)
28-
29-
30-
6+
Use an input processor to apply processing to input values and return the result. For example, you can use a [clamp](built-in-processors.md#clamp) processor to clamp values to within a certain range.
7+
8+
|Topic|Description|
9+
|-|-|
10+
|[Introduction to processors](introduction-to-processors.md) |Learn what processors can do to alter input values, and how they interact with bindings, actions, and controls. |
11+
|[Built-in processors](built-in-processors.md) | Explore the processors that come built into the Input System. |
12+
|[Write custom processors](write-custom-processors.md) | Create and register your own processors for use with bindings, actions, and controls. |
13+
|[Add processors to bindings and actions](add-processors-bindings-actions.md) |Add processors to individual bindings, or to all bindings on an action, via the Editor or via code. |
14+
|[Add processors to controls](add-processors-controls.md) | Add processors to specific control inputs, including custom controls. |

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858
* [Controls schemes](control-schemes.md)
5959
* [Interactions](interactions.md)
6060
* [Processors](processors.md)
61-
* [Configure sctions](configure-actions.md)
61+
* [Introduction to processors](introduction-to-processors.md)
62+
* [Built-in processors](built-in-processors.md)
63+
* [Write custom processors](write-custom-processors.md)
64+
* [Add processors to bindings and actions](add-processors-bindings-actions.md)
65+
* [Add processors to controls](add-processors-controls.md)
6266
* [Input Actions Editor reference](actions-editor.md)
6367
* [Input Actions Editor window reference](input-actions-editor-window-reference.md)
6468
* [Action Properties panel reference](action-properties-panel-reference.md)
@@ -84,7 +88,6 @@
8488
* [Write custom interactions](write-custom-interactions.md)
8589
* [Devices](Devices.md)
8690
* [Controls](controls.md)
87-
* [Processors](Processors.md)
8891
* [Player Input Component](player-input-component.md)
8992
* [Player Input Manager Component](PlayerInputManager.md)
9093
* [Input settings](Settings.md)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Add processors to bindings and actions
2+
3+
To add a processor to an [action](actions.md) or [binding](ActionBindings.md) via the Input Actions Editor:
4+
5+
1. Select the action or binding you want to add processors to. The Properties panel opens in the right pane of the window.
6+
1. In the Properties panel, navigate to the **Processors** foldout. Select the **Add (+)** icon on the header to open a list of all available processors that match your control type.
7+
1. From the drop-down list, select a processor type. A processor of that type appears in the __Processors__ foldout.
8+
1. In the __Processors__ foldout, edit any parameters of the processor.
9+
10+
<br/>![An example of the Processors foldout in the Properties panel, displaying processors called Stick Deadzone and Scale Vactor 2](Images/BindingProcessors.png)
11+
12+
To remove a processor, select the **Remove (-)** icon next to it. You can also use the up and down arrows to change the order of processors. This affects the order in which the system processes values.
13+
14+
To add a processor to an action or binding via code, use the following code examples as templates:
15+
16+
**Actions:**
17+
18+
```CSharp
19+
var action = new InputAction(processors: "invertVector2(invertX=false)");
20+
```
21+
22+
**Bindings:**
23+
24+
```CSharp
25+
var action = new InputAction();
26+
action.AddBinding("<Gamepad>/leftStick")
27+
.WithProcessor("invertVector2(invertX=false)");
28+
```
29+
30+
>[!NOTE]
31+
>The received value and result value must be of the same type. To convert received input values into different types, see [composite Bindings](ActionBindings.md#composite-bindings).
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Add processors to controls
2+
3+
The Input System automatically adds processors to a Control during device creation if they're specified in the Control's [layout](layouts.md).
4+
5+
You can't add processors to existing Controls after they've been created. You can only add processors to Controls when you're [creating custom devices](Devices.md#creating-custom-devices).
6+
7+
If you're using a layout generated by the Input System from a [state struct](Devices.md#step-1-the-state-struct) using [`InputControlAttributes`](../api/UnityEngine.InputSystem.Layouts.InputControlAttribute.html), you can specify the processors you want to use via the [`processors`](../api/UnityEngine.InputSystem.Layouts.InputControlAttribute.html#UnityEngine_InputSystem_Layouts_InputControlAttribute_processors) property of the attribute, like this:
8+
9+
```CSharp
10+
public struct MyDeviceState : IInputStateTypeInfo
11+
{
12+
public FourCC format => return new FourCC('M', 'Y', 'D', 'V');
13+
14+
// Add an axis deadzone to the Control to ignore values
15+
// smaller then 0.2, as our Control does not have a stable
16+
// resting position.
17+
[InputControl(layout = "Axis", processors = "AxisDeadzone(min=0.2)")]
18+
public short axis;
19+
}
20+
```
21+
22+
If you [create a layout from JSON](layouts.md#layout-from-json), you can specify processors on your Controls like this:
23+
24+
```json
25+
{
26+
"name" : "MyDevice",
27+
"extend" : "Gamepad", // Or some other thing
28+
"controls" : [
29+
{
30+
"name" : "axis",
31+
"layout" : "Axis",
32+
"offset" : 4,
33+
"format" : "FLT",
34+
"processors" : "AxisDeadzone(min=0.2)"
35+
}
36+
]
37+
}
38+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Built-in Processors
2+
3+
The Input System package comes with a set of built-in Processors, which you can use with [bindings](ActionBindings.md), [actions](actions.md) and [controls](controls.md).
4+
5+
6+
|**Processor name**|**Description**|**Operand type**|**Parameters**|
7+
|---|---|---|---|
8+
|[`Clamp`](../api/UnityEngine.InputSystem.Processors.ClampProcessor.html)|Clamps input values to the [`min`..`max`] range.|`float`|<ul><li>`float min`</li><li>`float max`</li></ul>|
9+
|[`Invert`](../api/UnityEngine.InputSystem.Processors.InvertProcessor.html)|Inverts the values from a Control (that is, multiplies the values by &minus;1).|`float`|None|
10+
|[`InvertVector2`](../api/UnityEngine.InputSystem.Processors.InvertVector2Processor.html)|Inverts the values from a Control (that is, multiplies the values by &minus;1). Inverts the x-axis of the vector if `invertX` is true, and the y-axis if `invertY` is true.|`Vector2`|<ul><li>`bool invertX`</li><li>`bool invertY`</li></ul>|
11+
|[`Invert Vector 3`](../api/UnityEngine.InputSystem.Processors.InvertVector3Processor.html)|Inverts the values from a Control (that is, multiplies the values by &minus;1). Inverts the x-axis of the vector if `invertX` is true, the y-axis if `invertY` is true, and the z-axis if `invertZ` is true.|`Vector3`|<ul><li>`bool invertX`</li><li>`bool invertY`</li><li>`bool invertZ`</li></ul>|
12+
|[`Normalize`](../api/UnityEngine.InputSystem.Processors.NormalizeProcessor.html)|Normalizes input values in the range [`min`..`max`] to unsigned normalized form [0..1] if `min` is >= `zero`, and to signed normalized form [-1..1] if `min` < `zero`.|`float`|<ul><li>`float min`</li><li>`float max`</li><li>`float zero`</li></ul>|
13+
|[`NormalizeVector2`](../api/UnityEngine.InputSystem.Processors.NormalizeVector2Processor.html)|Normalizes input vectors to be of unit length (1). This is the same as calling `Vector2.normalized`.|`Vector2`|None|
14+
|[`NormalizeVector3`](../api/UnityEngine.InputSystem.Processors.NormalizeVector3Processor.html)|Normalizes input vectors to be of unit length (1). This is the same as calling `Vector3.normalized`.|`Vector3`|None|
15+
|[`Scale`](../api/UnityEngine.InputSystem.Processors.ScaleProcessor.html)|Multiplies all input values by `factor`.|`float`|`float factor`|
16+
|[`ScaleVector2`](../api/UnityEngine.InputSystem.Processors.ScaleVector2Processor.html)|Multiplies all input values by `x` along the x-axis and by `y` along the y-axis.|`Vector2`|<ul><li>`float x`</li><li>`float y`</li></ul>|
17+
|[`ScaleVector3`](../api/UnityEngine.InputSystem.Processors.ScaleVector3Processor.html)|Multiplies all input values by `x` along the x-axis, by `y` along the y-axis, and by `z` along the z-axis.|`Vector3`|<ul><li>`float x`</li><li>`float y`</li><li>`float z`</li></ul>|
18+
|[`AxisDeadzone`](../api/UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor.html)|Scales the values of a Control so that any value with an absolute value smaller than `min` is 0, and any value with an absolute value larger than `max` is 1 or &minus;1.<br/><br/>Many Controls don't have a precise resting point (that is, they don't always report exactly 0 when the Control is in the center). Using the `min` value on a deadzone Processor avoids unintentional input from such Controls. Also, some Controls don't consistently report their maximum values when moving the axis all the way. Using the `max` value on a deadzone Processor ensures that you always get the maximum value in such cases.|`float`|<ul><li>`float min`</li><li>`float max`</li></ul>|
19+
|[`StickDeadzone`](../api/UnityEngine.InputSystem.Processors.StickDeadzoneProcessor.html)|Scales the values of a Vector2 Control, such as a stick, so that any input vector with a magnitude smaller than `min` results in (0,0), and any input vector with a magnitude greater than `max` is normalized to length 1.<br/><br/>Many Controls don't have a precise resting point (that is, they don't always report exactly 0,0 when the Control is in the center). Using the `min` value on a deadzone Processor avoids unintentional input from such Controls. Also, some Controls don't consistently report their maximum values when moving the axis all the way. Using the `max` value on a deadzone Processor ensures that you always get the maximum value in such cases.|`Vector2`|<ul><li>`float min`</li><li>`float max`</li></ul>
20+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Introduction to processors
2+
3+
Input processors apply processing to input values, and return the result. The Input System’s [built-in processors](built-in-processors.md) can apply value clamping, scaling, normalization, inversion, and deadzones. You can also create [custom processors](write-custom-processors.md) to apply additional data processing to input values.
4+
5+
You can install processors on [bindings](ActionBindings.md), [actions](actions.md) or [controls](controls.md). The Input System [registers](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_RegisterProcessor__1_System_String_) each processor with a unique name. This means that if you need to replace an existing processor, you need to register the new processor under the name of the existing processor.
6+
7+
Processors can have boolean, integer, and floating-point number parameters. When created in data such as [bindings](./ActionBindings.md), processors are described as strings that look like function calls.
8+
9+
For example, the following string references the processor registered as "scale" and sets its "factor" parameter to a floating-point value of 2.5:
10+
11+
```CSharp
12+
"scale(factor=2.5)"
13+
```
14+
15+
Multiple processors can be chained together. The Input System processes them in the order they appear in code. For example, the following string inverts a value, then normalizes [0..10] values to [0..1]:
16+
17+
```CSharp
18+
"invert,normalize(min=0,max=10)"
19+
```
20+
21+
## Processors on bindings and actions
22+
23+
When you create bindings for your [actions](actions.md), you can choose to add processors to the bindings. These process the values from the controls they bind to, before the system applies them to the action value. For example, you could invert the `Vector2` values from the controls along the Y axis before passing the values to the associated action.
24+
25+
Processors on actions work the same way, but affect all bindings on an action.
26+
27+
If there are processors on both the binding and the action, the Input System processes the processors from the binding first.
28+
29+
To apply a processor to a binding or action, refer to [Add processors to bindings and actions](add-processors-bindings-actions.md).
30+
31+
## Processors on controls
32+
33+
You can have any number of processors directly on an [`InputControl`](../api/UnityEngine.InputSystem.InputControl.html), which then process the values read from the Control. Whenever you call [`ReadValue`](../api/UnityEngine.InputSystem.InputControl-1.html#UnityEngine_InputSystem_InputControl_1_ReadValue) on a Control, all processors on that Control process the value before it gets returned to you. You can use [`ReadUnprocessedValue`](../api/UnityEngine.InputSystem.InputControl-1.html#UnityEngine_InputSystem_InputControl_1_ReadUnprocessedValue) on a Control to bypass the processors.
34+
35+
The devices that the Input System supports out of the box already have some useful processors added to their controls by default. For example, sticks on gamepads have a [Stick Deadzone](built-in-processors.md#stick-deadzone) processor.
36+
37+
To apply a processor to a control, refer to [Add processors to controls](add-processors-controls.md)

Packages/com.unity.inputsystem/Documentation~/predefined-processors.md

Lines changed: 0 additions & 108 deletions
This file was deleted.

Packages/com.unity.inputsystem/Documentation~/processors-on-actions.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)