Getting Started


ArborHeader

Information “Arbor: State Diagram Editor”

  • I want to make games using the finite state machine in Unity!
  • However, behavior that depends on the game logic want to coding on your own!
  • And the edit window of likely finite state machine used at such time,
    It is a simple state machine asset to write the state of the script to match the behavior you want to create.

What is finite state machine (FSM)?

  • The finite state machine, and behavior in a certain state, it is a mechanism for transition from the state to another.
  • For example, switches and lights.
  • The switch and the lamp there is a state of ON and OFF, will also be ON lamp if the ON switch.
  • Switch is switched to ON If you press, is the behavior to switch to OFF and press again.
  • Electric light will be the behavior to put the lights if ON.

Use far from in the game

Many of the game, I think I would be represented in the transition of state and behavior.
For example, the enemy of the movement might be as follows.

  • “Awake state”.
    Enemy it takes a generation motion Once generated.
    After the motion ends, the transition to “patrol state”.
  • “Patrol state”.
    Consider How trying it while appropriately patrol.
    When are near the player, the transition if the HP high of enemy itself to the “tracking state”.
    The transition if HP low to “escape state”.
  • “Tracking state”.
    To move to a position where you can attack the player.
    After arriving in the attack can be located, a transition is made to “attack the state.”
  • “Attacking state”.
    Attack!
    After the end of the attack motion, it returns to the “patrol state”.
  • “Escape state”.
    I run away from the found player.
    With confidence when away far to return to the “patrol state”.

In this example, we have branch whether to flee or to track in their own HP.
Although it is a branch of in just one place, I do not know immediately that you are where How about led When I was in the sentence.
If you are a complex movement, such as the final boss is also complicated and also behavior state is impossible also possible that further work is more of a state machine.
Patrol time there, some time fled, behavior in the finely script called,
After that better to the shape you want to edit the relationship between the transition in the editor will think whether to also improve well become the development efficiency is visual.

You can use the Arbor, you can partnering in this way the transition of visual state.

ExampleEnemyAI

Get the Arbor

How to use

Additional ArborFSM

  • Choose you want to apply GameObject
  • Select “menu> Component> Arbor> ArborFSM”.
    ArborFSMの追加
  • Alternatively, select the “Add Component button> Arbor> ArborFSM” of Inspector.
    ArborFSMの追加(Add Componentから)
  • In addition, GameObject from the Hierarchy of the Create button “Arbor> ArborFSM” state ArborFSM is attached can create.
    HierarchyのCreateボタンから作成

Open the Arbor Editor

  • Click on the ArborFSM Open Editor button that you want to edit.
    Arbor Editorを開く(Open Editorボタンから)
    Alternatively, select the “Menu> Window> Arbor Editor”

Selection of ArborFSM

  • Arbor Editor and drag-and-drop to the top of the selection box.
    Or selected from the list by clicking on the selection box.
    Select ArborFSM
  • Automatically become selected state when you press the Open Editor button in the Inspector of ArborFSM.

Creating States

  • Right-click the appropriate position of Arbor Editor.
  • Click on the “Create State”.
    Create State

The name change of state

  • Change the text box of the state frame in the upper

Specifying the starting state

The starting state, when an object is activated, it is the state that is executed at the beginning most.
It will automatically start state when you create a state in the absence of starting state.

  • Click on the state name next to the setting icon.
    Open State Settings
  • Click on the “Set Start State.”
    Set Start State

Delete State

  • Click to select the state.
  • Right-click and click the “Delete”.
    Delete State

Add the behavior in the state

  • Click on the state name next to the setting icon.
  • Select “Add Behaviour”.
    Add Behaviour
  • Select the behavior you want to add from the behavior list.
    ステートに挙動を追加2
    (Free version, Lite version for built-in behavior has not been shipped, it is necessary to write your own script.)
  • It may assert a direct drag-and-drop script file you want to add behavior.

Delete of behavior

  • Click the behavior name next to the setting icon.
    Open Behaviour Settings
  • Click the “Delete”.
    Delete Behaviour

The behavior on transition(Normal Version only)

Behavior on the transition is built some from the beginning.

  • Select “Add Behaviour” from the settings icon next to the state name.
    ステートに挙動を追加1
  • Behavior of the transition system is contained within the Transition.
    TransitionBehaviours
  • There is such TimeTransition to transition in time.

Connection from the behavior to the state

  • It advance is adding the behavior of the transition system such as TimeTransition.
  • The drag-and-drop from the state connection area to another State.
    GIF
  • Canceled if tied at nothing
    GIF

About Resident State

Resident state constantly movement state, and then use when you want to forcibly interrupted pending (such as collisions).
Please be careful to point instead to continue the movement does not accept a transition from other states.

  • Right-click the appropriate position of Arbor Editor.
  • Click the “Create Resident State”.
    CreateResidentState
  • State that you create will be green special state.
    ResidentState

Parameters container(Normal Version only)

  • Choose you want to apply GameObject
  • Select “menu> Component> Arbor> ParameterContainer”.
    Alternatively, select the “Add Component button> Arbor> ParameterContainer” of Inspector.
  • Additional parameters.
    From the right side of the + button in the “Parameters”, select the type you want to add (Int / Float / Bool).
    ParameterContainer2
  • Edit
    Name, select a value editing.
    ParameterContainer3
  • Delete parameters.
    Parameters right – Click the button.

State List

  • Open and close by clicking on the “State List” in the toolbar.
    Open State List
  • A list of state is displayed on the left side is selected by clicking the state.
    GIF
  • From the search bar, search by name (some matches), Search by type of behavior (match-all) is possible.
    GIF

Choose how to specify the value

  • If there is a field next to ▼ mark of each property, you can choose how to specify the value by clicking.
    Flexibleタイプの選択2
  • Unlike the choice depending on the type of value, it is as follows for the Lord.
    • Constant
      Specify a fixed value
    • Parameter
      Refer to the parameter
    • Random
      Get at random from within the specified range.
    • Calculator
      It accepts the input from the operation node.

For calculator node (ver 2.0.0 or later)

By the calculator node, input and output and operation of the variable you will be able to on the Arbor Editor.

Creating a calculator node

  • Right-click the appropriate position of Arbor Editor.
  • Click on the “Create Calculator”.
  • Select the calculator node you want to create from the list
    演算ノードの作成2

Connection of the calculator slot

  • To be connected by dragging and dropping the input or output slots
    GIF

Coding

You can prepare the behavior and the processing of your own to create a script of C#, JavaScript,Boo.

If you want to use Javascript or Boo

  1. If there is no following Plugins folder in Assets, Create Plugins folder
  2. Create Arbor folder in the Plugins folder
  3. Arbor / Internal / Scripts folder in the move in its created Arbor folder and change the name to the Internal.
  4. Arbor / Core / Scripts folder in the move in its created Arbor folder and change the name to the Core.

Creating a script file

  • Right-click on the location you want to create from the Project window.
  • From the right-click menu, and select your favorite language from the “Create> Arbor > State Behaviour”.
    スクリプトファイルの作成
  • Determined to enter the file name

State Connection

  • Declare StateLink wearing a public or SerializeField attribute to the script that you have created.
    The declaration automatically become editable Arbor Editor if.

    using UnityEngine;
    using System.Collections;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour {
    	public StateLink nextState;
    	// Approximately
    }
    

    State Connection from script

  • It is referred to as the Transition in the transition you want to timing.
    Transition( nextState );
    

Input from the calculator node

  • Declare and InputSlotInt and InputSlotFloat wearing a public or SerializeField attribute to create scripts.
    (For InputSlot<T> generic class can not be serialized on the Unity of the specification, please use the class was always inherited)
    Automatically become editable Arbor Editor if the declaration.

    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour
    {
    	public InputSlotInt slotInt;
    }
    

    %e6%bc%94%e7%ae%97%e3%83%8e%e3%83%bc%e3%83%89%e3%81%8b%e3%82%89%e3%81%ae%e5%85%a5%e5%8a%9b%e4%be%8b

  • To get the value is to use the GetValue method.
    int data = 0;
    slotInt.GetValue(ref data);
    if (data == 10)
    {
    	Debug.Log("Test");
    }
    

Input from the calculator node(Flexible)

  • Declare and FlexibleInt and FlexibleFloat wearing a public or SerializeField attribute to create scripts.
    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour
    {
    	public FlexibleInt flexible;
    }
    

    %e6%bc%94%e7%ae%97%e3%83%8e%e3%83%bc%e3%83%89%e3%81%8b%e3%82%89%e3%81%ae%e5%85%a5%e5%8a%9b%e4%be%8bflexible
    If you select Calculucator in ArborEditor window accepts an input from the computing node.

  • To get the value is to use the value property.
    if (flexible.value == 10)
    {
    	Debug.Log("Test");
    }
    

Output to the calculator node

  • Declare and OutputSlotInt and OutputSlotFloat wearing a public or SerializeField attribute to create scripts.
    (For OutputSlot<T> generic class is not serialized on the Unity of the specification, please use the class was always inherited)
    Automatically become editable Arbor Editor if the declaration.

    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour
    {
    	public OutputSlotInt slotInt;
    }
    

    %e6%bc%94%e7%ae%97%e3%83%8e%e3%83%bc%e3%83%89%e3%81%b8%e3%81%ae%e5%87%ba%e5%8a%9b%e4%be%8b

  • To set the value to use the SetValue method.
    slotInt.SetValue(10);
    

Editor extension

  • Such as available inspector extension and PropertyDrawer is I can also be used to StateBehaviour in Unity

Important point

  • For enabled of MonoBehaviour are used internally already for execution control, please use the behaviourEnabled to be a substitute.

To the next step