Templates
One of the most interesting possibilities of our API is the ability to build scripts 'template' programmatically. The steps to follow for this are:
Create a C# script that inherits from
GFBehaviour
.Implement the
OnInit()
method describing the initial configuration of default blocks that we want using methods.
The OnInit()
method will be executed automatically every time we add our script to a GameObject, allowing us to use a series of specialized methods to add blocks to the script just as we would in the Editor, thus converting the script into a template .
Let's see below the methods to use to add the different types of blocks available in GameFlow.
Independent blocks
Are those blocks that do not require to be contained in other blocks to exist and therefore can be seen in the primel level or root level of our script derived from GFBehaviour
. In our example (see end) would be the On Start, Note and State Machine blocks.
To add these blocks to the script we use the AddBlock<T>()
method in which we must replace T
with the name of the class that represents the block. This method will add the block and return a reference to it that we can use for our next operations.
The list of classes that represent independent blocks is the following:
Program
Data
Documentation
Tool
Actions
The actions are not independent blocks and therefore must be added using the AddAction<T>()
method of that program, state or action that will contain it, where T
must be replaced by the name of the class that represents the action, which will normally be the name of the action without spaces (for example, the class for the action 'Set Rotation' would be SetRotation
). The complete list of available actions can be found in the Actions Reference.
Apart from all programs and states, the list of action classes that support the AddAction<T>()
method is the following:
This method will return a reference to the created action that we can use to, for example, modify some of its properties.
Conditions
Conditions are even less independent blocks than actions, since they can only be added to a few specific actions that support the AddCondition<T>
method, where T
must be replaced by the name of the class representing the condition to be added. The complete list of available conditions can be found in the Conditions Reference.
The list of action classes that support the AddCondition<T>()
method is as follows:
This method will return a reference to the created condition that we can use to, for example, modify some of its properties.
States
The states (class State) are not independent blocks either, since they can only live within class blocks StateMachine. In this case the method to be used is a simple and direct AddState()
without type specification.
This method will return a reference to the created state that we can use to add actions to it.
Example
In the following example we will build a custom template script to which we will add a program, a note and a state machine:
The result of adding our MyGF script to a GameObject would be this:
Last updated