For this time, we will make an easy mechanism to switch ON / OFF at 1 second intervals.
- 1 Operating environment
- 2 Create tutorial project
- 3 Create ArborFSM object
- 4 Displaying the Arbor Editor window
- 5 Create OFF state
- 6 Create ON state
- 7 About “Start state”
- 8 Switch state over time
- 9 Setting the ON state
- 10 Confirm the operation so far
- 11 Create a Cube object
- 12 Deactivate in OFF state
- 13 Activate in ON state
- 14 Operation check
- 15 Next step
This tutorial is created in the following environment.
- Unity 5.3.0f4
- Arbor 2.2.0
Depending on the version, please understand that there are parts different from the explanation.
Create tutorial project
First of all, please create a project for the tutorial.
|Assets to import||Arbor|
For information on creating projects and importing Arbor, please refer to “Get Started : Preparation for using Arbor”.
Create ArborFSM object
Create an ArborFSM object to make the state machine available.
From the Create button of the Hierarchy window, select “Arbor> ArborFSM” to create a GameObject with ArborFSM component.
This ArborFSM is a component for operating the state machine.
Displaying the Arbor Editor window
To edit ArborFSM, do it in the Arbor Editor window instead of the Inspector window.
Please click on the Open Editor button in Inspector of ArborFSM to display it.
When clicked, the Arbor Editor window with ArborFSM selected is displayed.
Since you will often use the Arbor Editor window, it’s a good idea to dock it in an easy-to-use position.
Create OFF state
Since we only handle two states ON / OFF this time, we will first create two states.
First, right click on a place where there is nothing on the graph and select “Create State”.
Since the name of the state is named “New State”, we recommend changing to a meaningful name.
In this example, set the state name to “OFF”.
Create ON state
Continue to create an ON state.
Just like “Create OFF State”, right click on the part of the graph where there is nothing and select “Create State”.
Let the state name be “ON”.
About “Start state”
When you create a state from nothing, the state you created the first time becomes the “Start state”.
“Start state” is the state that becomes effective at the beginning of execution.
In this case, the OFF state is set to “Start state”.
To change “Start state”, click the setting icon of “Normal state” and select “Set Start State”.
In this time, the OFF state is “Start state” so it will not be a problem so I will put it back.
Switch state over time
Next, we will set the behavior of the state.
To add behaviors, perform “Add Behaviour” from the setting icon.
Click the OFF state setting icon and select “Add Behaviour”.
Since we want to transition over time, we add “Transition> TimeTransition” here.
TimeTransition transitions to the state specified in “Next State” after the number of seconds specified in “Seconds” elapses.
For this time we will set the transition time to 1 second.
Set Seconds of TimeTransition to 1.
Then, specify “Next State” to transition to the ON state.
Please drag and drop the “Next State” button to the ON state.
Now it will transition to the ON state after 1 second has elapsed.
For more information about TimeTransition, see TimeTransition reference.
In addition, Arbor has built-in behaviour of 100 or more beforehand, so please refer to Arbor reference for what behavior is there.
Setting the ON state
In the ON state as well, we will set it to transition over time.
Since there is a TimeTransition already set to the OFF state, copy and paste is performed.
First, click the TimeTransition setting icon in the OFF state and select “Copy”.
Next, click on the setting icon in the ON state and select “Paste Behaviour”.
Including each parameter of TimeTransition was copied and pasted.
I want to transition from the Time state TimeTransition to the OFF state, so reconnect the “Next State” to the OFF state.
This made it possible to switch ON / OFF at 1 second intervals.
Confirm the operation so far
Let’s try once and check the operation.
Press “Play button” to execute.
If you look at the Arbor Editor window during execution, you can see that “Current State” switches at 1 second intervals.
However, since you can not see any change in Game View as it is, leave the Cube behind and let it look visually.
Create a Cube object
From the Create button of Hierarchy, select “3D Object> Cube”.
A Cube object was created in the scene.
Deactivate in OFF state
In the OFF state, you want to inactivate the Cube object, so use ActivateGameObject to set it.
Click the OFF state setting icon, select “Add Behaviour”, select “GameObject> ActivateGameObject” and add it.
When ActivateGameObject is added, make setting.
Leave “Target” to Cube, “Begin Active” and “End Active” unchecked.
This makes the Cube object inactive in the OFF state.
For more information about ActivateGameObject, see ActivateGameObject reference.
Activate in ON state
Since we want to activate the Cube object when entering the ON state, we set it by using ActivateGameObject like the OFF state.
Again, let’s copy and paste from the ActivateGameObject in the OFF state.
Select “Copy” from the setting icon of the ActivateGameObject in the OFF state, and select “Paste Behaviour” from the setting icon of the ON state.
Copy and paste was done with the Cube object set to “Target”.
Next, in the ON state, you want to activate it, so check “Begin Active” and “End Active”.
This will activate the Cube object when entering the ON state.
Let’s check at the end whether the Cube object will be switched or not.
Press “Play button” to execute.
Now you can see that the Cube object’s activity switches at 1 second intervals.
If you also check the Arbor Editor window, you can see that the Cube object is switched normally in conjunction with the state change.
This completes the “Basic”.
Next time is “Coding”.
I will explain how to create Arbor scripts.