Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
NEW: 'Stick' interaction.
- Loading branch information
Rene Damm
committed
Jul 27, 2018
1 parent
5c94619
commit 430b36e
Showing
6 changed files
with
149 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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
38 changes: 38 additions & 0 deletions
38
Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/StickInteraction.cs
This file contains 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,38 @@ | ||
| ////REVIEW: this should not have to cast to InputControl<Vector2>; interactions should have the same | ||
| //// ReadValue<TValue>() API available to them that action callbacks do; this way this interaction | ||
| //// here, for example, will also work with composites | ||
|
|
||
| namespace UnityEngine.Experimental.Input.Interactions | ||
| { | ||
| /// <summary> | ||
| /// Starts when stick leaves deadzone, performs while stick moves outside | ||
| /// of deadzone, cancels when stick goes back into deadzone. | ||
| /// </summary> | ||
| public class StickInteraction : IInputInteraction | ||
| { | ||
| public void Process(ref InputInteractionContext context) | ||
| { | ||
| var stick = context.control as InputControl<Vector2>; | ||
| if (stick == null) | ||
| return; | ||
|
|
||
| var value = stick.ReadValue(); | ||
| if (value.x > 0 && value.y > 0) | ||
| { | ||
| if (!context.isStarted) | ||
| context.Started(); | ||
| else | ||
| context.PerformedAndStayStarted(); | ||
| } | ||
| else if (context.isStarted) | ||
| { | ||
| // Went back to below deadzone. | ||
| context.Cancelled(); | ||
| } | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/StickInteraction.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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