Behavior

What is a Behavior?


A Behavior is a simple C# class and is responsible for running a Mapping. It follows the common TAI Scriptable Object pattern of having its key logic located in its type, Behavior Type, so that it is easy to create new Behavior Types and plug them into Action Types. The Behavior contains all of the logic for dealing with starting, running, interrupting, and finishing a Mapping. See Behavior Flow section below for details on how a Behavior runs a Mapping.

Every Agent has one Behavior class that it references. It uses the Agent's Coroutines feature to run the Behavior Flow in a separate timing loop.

Behavior Flow



Click on the diagram for full size.

Behavior Type


Script Reference

All of the key logic in a Behavior is located in the BehaviorType. The following functions must be implememented:


    public abstract void SetContext();
    public abstract StartBehavior();
    public abstract bool IsFinished();
    public abstract UpdateBehavior();
    public abstract FinishBehavior();
    public abstract InterruptBehavior();
        

Most BehaviorTypes rely on an Agent's Attributes for key values. For example the GoToBT requires a MinMaxFloatAT, Attribute Type for a float value that is between min and max, to be specified in the Mapping Type. BehaviorType accomplishes this through the BehaviorType's EditorHelp class. The MappingType Custom Inspector uses the EditorHelp class to show the apprpriate fields for creating a Selector for a MinMaxFloatAT.

Context


Since a Behavior Type is a Scriptable Object it can't retain state but many Behavior Types require state to be saved. For example a simple WaitBT would need to remember the start time. The Context class allows this required state to be saved and also allows each Behavior Type to define its own data. It is saved by using a Dictionary mapping Agent to Context. (Dictionary<Agent, Context>)