-
Notifications
You must be signed in to change notification settings - Fork 323
DOCS: How to use processors #2171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ritamerkl
wants to merge
14
commits into
develop
Choose a base branch
from
docs-processors
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
55f2803
restructure processors documentation
ritamerkl 8472341
added scenarios for each processor
ritamerkl 1bfff7b
uniforming scenarios & explanation and adding more details
ritamerkl db25dc2
added pictures and code
ritamerkl 5e9ee17
refined scenarios and added pictures
ritamerkl d37dcd5
added example for clamp processor with picture
ritamerkl c824127
replaced image for clamp processor
ritamerkl 32317b2
corrected grammar and spelling
ritamerkl c365673
Merge branch 'develop' into docs-processors
ritamerkl 1218ba0
fixed formatting
ritamerkl bbea9d6
Merge branch 'docs-processors' of https://github.com/Unity-Technologi…
ritamerkl 3bc0a6e
updated file references to processors
ritamerkl 58a726e
fixed docs link
ritamerkl bc03750
Fixed Doc link
ritamerkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Packages/com.unity.inputsystem/Documentation~/HowToApplyProcessors.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||||||||||||
--- | ||||||||||||||||
uid: input-system-processors | ||||||||||||||||
--- | ||||||||||||||||
# How to apply Processors | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
The particularities between the three different ways of applying Processors to input events. For more information on the general usage of Processors refer to [Using Processors](UsingProcessors.md). | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
* [Processors on Bindings](#processors-on-bindings) | ||||||||||||||||
* [Processors on Actions](#processors-on-actions) | ||||||||||||||||
* [Processors on Controls](#processors-on-controls) | ||||||||||||||||
|
||||||||||||||||
## Processors on Bindings | ||||||||||||||||
|
||||||||||||||||
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 instance, you might want to invert the `Vector2` values from the controls along the Y axis before passing these values to the Action that drives the input logic for your application. To do this, you can add an [Invert Vector2](ProcessorTypes.md#invert-vector-2) Processor to your Binding. | ||||||||||||||||
|
||||||||||||||||
If you're using Actions defined in the [Input Actions Editor](ActionsEditor.md), or in an [Action Asset](ActionAssets.md), you can add any Processor to your Bindings in the Input Action editor. Select the Binding you want to add Processors to so that the right pane of the window displays the properties for that Binding. Select the Add (+) icon on the __Processors__ foldout to open a list of all available Processors that match your control type, then choose a Processor type to add a Processor instance of that type. The Processor now appears under the __Processors__ foldout. If the Processor has any parameters, you can edit them in the __Processors__ foldout. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
 | ||||||||||||||||
|
||||||||||||||||
To remove a Processor, click 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. | ||||||||||||||||
|
||||||||||||||||
If you create your Bindings in code, you can add Processors like this: | ||||||||||||||||
|
||||||||||||||||
```CSharp | ||||||||||||||||
var action = new InputAction(); | ||||||||||||||||
action.AddBinding("<Gamepad>/leftStick") | ||||||||||||||||
.WithProcessor("invertVector2(invertX=false)"); | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
## Processors on Actions | ||||||||||||||||
|
||||||||||||||||
Processors on Actions work in the same way as Processors on Bindings, but they affect all controls bound to an Action, rather than just the controls from a specific Binding. If there are Processors on both the Binding and the Action, the system processes the ones from the Binding first. | ||||||||||||||||
|
||||||||||||||||
You can add and edit Processors on Actions in the [Input Actions Editor](ActionsEditor.md), or in an [Action Asset](ActionAssets.md) the [same way](#processors-on-bindings) as you would for Bindings: select an Action to edit, then add one or more Processors in the right window pane. | ||||||||||||||||
|
||||||||||||||||
If you create your Actions in code, you can add Processors like this: | ||||||||||||||||
|
||||||||||||||||
```CSharp | ||||||||||||||||
var action = new InputAction(processors: "invertVector2(invertX=false)"); | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
## Processors on Controls | ||||||||||||||||
|
||||||||||||||||
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. | ||||||||||||||||
|
||||||||||||||||
The Input System adds Processors to a Control during device creation, if they're specified in the Control's [layout](Layouts.md). You can't add Processors to existing Controls after they've been created, so you can only add Processors to Controls when you're [creating custom devices](Devices.md#creating-custom-devices). The devices that the Input System supports out of the box already have some useful Processors added on their Controls. For instance, sticks on gamepads have a [Stick Deadzone](ProcessorTypes.md#stick-deadzone) Processor. | ||||||||||||||||
|
||||||||||||||||
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: | ||||||||||||||||
|
||||||||||||||||
```CSharp | ||||||||||||||||
public struct MyDeviceState : IInputStateTypeInfo | ||||||||||||||||
{ | ||||||||||||||||
public FourCC format => return new FourCC('M', 'Y', 'D', 'V'); | ||||||||||||||||
|
||||||||||||||||
// Add an axis deadzone to the Control to ignore values | ||||||||||||||||
// smaller then 0.2, as our Control does not have a stable | ||||||||||||||||
// resting position. | ||||||||||||||||
[InputControl(layout = "Axis", processors = "AxisDeadzone(min=0.2)")] | ||||||||||||||||
public short axis; | ||||||||||||||||
} | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
If you [create a layout from JSON](Layouts.md#layout-from-json), you can specify Processors on your Controls like this: | ||||||||||||||||
|
||||||||||||||||
```CSharp | ||||||||||||||||
{ | ||||||||||||||||
"name" : "MyDevice", | ||||||||||||||||
"extend" : "Gamepad", // Or some other thing | ||||||||||||||||
"controls" : [ | ||||||||||||||||
{ | ||||||||||||||||
"name" : "axis", | ||||||||||||||||
"layout" : "Axis", | ||||||||||||||||
"offset" : 4, | ||||||||||||||||
"format" : "FLT", | ||||||||||||||||
"processors" : "AxisDeadzone(min=0.2)" | ||||||||||||||||
} | ||||||||||||||||
] | ||||||||||||||||
} | ||||||||||||||||
``` |
Binary file added
BIN
+86 KB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Clamp-Editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+141 KB
...ages/com.unity.inputsystem/Documentation~/Images/Processors-Deadzone-Editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+72.4 KB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Invert-Editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+913 KB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Normalize-Fast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+913 KB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Normalize-Slow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+103 KB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-NormalizeAsset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+111 KB
...s/com.unity.inputsystem/Documentation~/Images/Processors-Scale-Look-Pointer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+115 KB
...ges/com.unity.inputsystem/Documentation~/Images/Processors-Scale-Look-Stick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+83.7 KB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Scale-Look.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.39 MB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Ship-Left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.4 MB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Ship-Neutral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.4 MB
Packages/com.unity.inputsystem/Documentation~/Images/Processors-Ship-Right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a package doc, use the standard DocFX note format shown below. Please update all the notes in this PR.