Skip to content

Commit f20ab31

Browse files
authored
Merge pull request #9 from ExtendRealityLtd/feat/proxyactiondocs
feat(HowToGuides): add guide for proxy actions
2 parents fb24bd6 + a46ae44 commit f20ab31

19 files changed

Lines changed: 732 additions & 0 deletions

Documentation/HowToGuides/CreatingProxyActionsAndChainingActions.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Creating Proxy Actions And Chaining Actions
2+
3+
> * Level: Beginner
4+
>
5+
> * Reading Time: 5 minutes
6+
>
7+
> * Checked with: Unity 2018.3.14f1
8+
9+
## Introduction
10+
11+
It is sometimes desirable to have many different input actions all have the same outcome. It is possible to simply do this by wiring up all of the events in all of the actions to have the same output, however this can get cumbersome and hard to maintain.
12+
13+
The [Zinnia] Actions can be used as proxies to enable chaining of Actions to all drive the same outcome defined in one place.
14+
15+
Following on from the scene created in [Using The Unity Button Action], we’re going to move the Action functionality to a Proxy Action and then chain the button press Action and keyboard Action to this newly created Proxy Action. This will move our output functionality into one place and allow us to call it from many different actions.
16+
17+
### Prerequistes
18+
19+
* A Unity Button Action exists in the scene. See [Using The Unity Button Action].
20+
21+
## Let's Start
22+
23+
### Step 1
24+
25+
Create an empty `GameObject` in the Unity Hierarchy and rename it to `FloorToggler` then click the `Add Component` button and select the `Boolean Action` component.
26+
This newly created `Boolean Action` will be the action that defines how we toggle the active state of the `Floor` GameObject.
27+
28+
![Creating The Floor Toggler](assets/images/CreatingTheFloorToggler.png)
29+
30+
### Step 2
31+
32+
Click the `+` symbol in the bottom right corner of the `Activated` event parameter in the `Boolean Action` component and then drag and drop the `Floor` GameObject into the box that appears and displays `None (Object)`.
33+
34+
![Creating The Boolean](assets/images/CreatingTheBoolean.png)
35+
36+
### Step 3
37+
38+
Do the same as Step 2 but for the `Deactivated` event parameter in the `Boolean Action` component, but tick the checkbox under the `GameObject.SetActive` function.
39+
40+
![Deactivating The Boolean](assets/images/DeactivatingTheBoolean.png)
41+
42+
### Step 4
43+
44+
Now we have a generic Action that will disable the `Floor` GameObject when the Action receives `true` and will re-enable the `Floor` GameObject when the Action receives `false`.
45+
46+
We could hook up the `Unity Input Manager Button Action` `Value Changed` event to simply call the `Receive` method on our `FloorToggler` GameObject `BooleanAction` component and this will pass the state of the `Unity Input Manager Button Action` over to the `Boolean Action` whenever the value changes. However, doing this means for every input action, we’d need to wire up their `Value Changed` event to point to the `Receive` method on our `BooleanAction` component. This can again get very cumbersome and hard to maintain, so instead we’re going to use the `Sources` parameter that is available on a `Zinnia.Action.`
47+
48+
The `Sources` parameter allows us to specify other Actions for our `BooleanAction` to monitor changes on and re-emit any events that happen on those source actions.
49+
50+
Expand the `Sources` parameter and enter the desired number of other Actions to monitor in the `Size` parameter field. In this example, we want to watch two other Actions (the `Input.UnityInputManager.ButtonAction` and the `Input.UnityInputManager.XboxController -> Input Actions -> ButtonA_Press[0]`) so enter `2` into the Sizes parameter field.
51+
52+
![Update Sources Parameter On Boolean Action](assets/images/UpdateSourcesParameterOnBooleanAction.png)
53+
54+
### Step 5
55+
56+
Drag and drop the `Input.UnityInputManager.ButtonAction` GameObject into the `Sources -> Size -> Element 0` slot on the `FloorToggler` GameObject `BooleanAction` component.
57+
58+
> This will link the `Input.UnityInputManager.ButtonAction` `BooleanAction` component as a source value for the `FloorToggler` `BooleanAction` component, which means whenever the `Input.UnityInputManager.ButtonAction` `BooleanAction` component value changes then it will automatically send that updated value to the `FloorToggler` `BooleanAction` component.
59+
60+
Drag and drop the `Input.UnityInputManager.XboxController -> Input Actions -> ButtonA_Press[0]` GameObject that contains the `Unity Input Manager Button Action` component that is working with the Xbox Controller A Button into the `Sources -> Size -> Element` 1 slot on the `FloorToggler` GameObject `BooleanAction` component as well.
61+
62+
![Drag and Drop Source Actions](assets/images/DragAndDropSourceActions.png)
63+
64+
### Step 6
65+
66+
The `Unity Input Manager Button Action` events still have actions to perform when either the Space Key is pressed or the Xbox Controller A Button is pressed, we no longer need those actions on those `Unity Input Manager Button Action` components now as they are being chained to our new `FloorToggler` GameObject `BooleanAction` component. So let’s remove the event listeners from the other `Unity Input Manager Button Action` components.
67+
68+
Select the `Input.UnityInputManager.XboxController -> Input Actions -> ButtonA_Press[0]` GameObject and click the `-` symbol in the bottom right corner of the `Activated` event parameter and the `Deactivated` event parameter on the `Unity Input Manager Button Action` component. This will remove those event listeners and make this `Unity Input Manager Button Action` component an Action that on its own does nothing other than listen for button presses on the Xbox Controller A Button.
69+
70+
![Remove Event Listeners From The Xbox Controller A Button](assets/images/RemoveEventListenersFromTheXboxControllerAButton.png)
71+
72+
Let’s do the same with the `Unity Input Manager Button Action` component on the `Input.UnityInputManager.ButtonAction` GameObject that is set up to listen for the Space Key press. Select the `Input.UnityInputManager.ButtonAction` GameObject and click the `-` symbol in the bottom right corner of the `Activated` event parameter and the `Deactivated` event parameter on the `Unity Input Manager Button Action` component.
73+
74+
![Remove Event Listeners From The Space Key.png](assets/images/RemoveEventListenersFromTheSpaceKey.png)
75+
76+
### Done
77+
78+
There is now a single defined action in the scene that controls the active state of the `Floor` GameObject and we’ve hooked up two other actions that deal with listening for input from the Space Key and the Xbox Controller Button A to perform the output action of toggling the floor state.
79+
80+
This ability to create a Proxy Action and then chain other Actions makes it possible to drive a single output Action based on multiple different input Actions.
81+
82+
Play the Unity scene and you will be able to press the Space Key to make the `Floor` GameObject disappear or you can press the Xbox Controller Button A to also make the `Floor` GameObject disappear.
83+
84+
[Zinnia]: https://github.com/ExtendRealityLtd/Zinnia.Unity
85+
[Using The Unity Button Action]: ../UsingTheUnityButtonAction/README.md

Documentation/HowToGuides/CreatingProxyActionsAndChainingActions/README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documentation/HowToGuides/CreatingProxyActionsAndChainingActions/assets.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documentation/HowToGuides/CreatingProxyActionsAndChainingActions/assets/images.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
34.6 KB
Loading

Documentation/HowToGuides/CreatingProxyActionsAndChainingActions/assets/images/CreatingTheBoolean.png.meta

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
30.3 KB
Loading

Documentation/HowToGuides/CreatingProxyActionsAndChainingActions/assets/images/CreatingTheFloorToggler.png.meta

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
11.2 KB
Loading

0 commit comments

Comments
 (0)