GameFlow
  • Overview
  • Installation
  • Hello, World!
  • Basics
  • Guides
    • Programs
    • Variables
    • Actions
    • Conditions
    • Flow Control
    • Parameters
    • Commands
    • Gamefabs
    • Lists
    • States
    • Vectors
    • Colors
    • GameObjects
    • Transforms
    • Game Management
    • Animation
    • Scene Management
    • Audio
    • Physics
    • Input Control
    • Maths
    • Text
    • Navigation
    • Paths
    • Object Pools
    • Raycasting
    • Timers
    • User Interface
    • 2D
    • Video
    • Materials
    • Shaders
    • Particles
    • Hierarchy
    • Application
    • Events
    • Camera
    • Other
    • Automation
    • Customization
    • Debugging
    • Documentation
    • Gizmos
    • Integration
    • Localization
    • Macros
    • Mobile
    • Multiplatform
    • Networking
    • Utilities
    • WebGL
    • Sharing
  • Reference
    • Programs
    • Actions
    • Conditions
    • Data
    • Tools
  • API
    • Custom Actions
    • Custom Conditions
    • Templates
    • Communication
    • Direct Execution
    • Event Listening
    • Reference
  • Tutorials
    • 01: Object rotation & Color change
    • 02: Moving a cube with Keys and Forces
    • 03: Simple camera shake effect
    • 04: Point and Click
    • 05: Typewriter
Powered by GitBook
On this page
  • Independent blocks
  • Actions
  • Conditions
  • States
  • Example
  1. API

Templates

PreviousCustom ConditionsNextCommunication

Last updated 3 years ago

One of the most interesting possibilities of our API is the ability to build scripts 'template' programmatically. The steps to follow for this are:

  1. Create a C# script that inherits from GFBehaviour.

  2. 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:

Block Type
Class

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 .

Apart from all programs and states, the list of action classes that support the AddAction<T>() method is the following:

Classes

This method will return a reference to the created action that we can use to, for example, modify some of its properties.

Conditions

The list of action classes that support the AddCondition<T>() method is as follows:

Classes

This method will return a reference to the created condition that we can use to, for example, modify some of its properties.

States

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:

using GameFlow;

namespace MyNamespace {

public class MyGF : GFBehaviour {

    protected override void OnInit() {
        // Add a On Start program with a Log Message action
        Program onStart = AddBlock<OnStart>();
        LogMessage logMessage = onStart.AddAction<LogMessage>();
        logMessage.message = "Hello!";
        // Add a Note
        Note note = AddBlock<Note>();
        note.text = "Just an example";
        // Add a State Machine with a State
        StateMachine sm = AddBlock<StateMachine>();
        sm.AddState("Hola");
    }
}

}

The result of adding our MyGF script to a GameObject would be this:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

, , ,

, ,

, , , , , , ,

, , , , , , , , ,

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 .

, , ,

The states (class ) are not independent blocks either, since they can only live within class blocks . In this case the method to be used is a simple and direct AddState() without type specification.

Actions Reference
Conditions Reference
State
StateMachine
Macro
OnActivate
OnApplicationFocus
OnApplicationInit
OnApplicationPause
OnApplicationQuit
OnAwake
OnClick
OnCollisionEnter
OnCollisionEnter2D
OnCollisionExit
OnCollisionExit2D
OnCollisionStay
OnCollisionStay2D
OnCustomEvent
OnDeactivate
OnDemand
OnDeselect
On Destroy
OnDrawGizmos
OnEndEdit
OnExternalMessage
OnFixedUpdate
OnGameOver
OnGamePause
OnGameResume
OnGameStart
OnLanguageSet
OnLateUpdate
OnMacroKey
OnMouseDown
OnMouseDrag
OnMouseEnter
OnMouseExit
OnMouseOver
OnMouseUp
OnParameterChange
OnPointerDown
OnPointerEnter
OnPointerExit
OnPointerUp
OnProgramFinish
OnSceneLoad
OnSelect
OnStart
OnTimerExpire
OnTriggerEnter
OnTriggerEnter 2D
OnTriggerExit
OnTriggerExit2D
OnTriggerStay
OnTriggerStay2D
OnUpdate
OnValueChange
OnVariableChange
List
Localization
Parameter
Variable
Description
Note
Separator
Command
Force
Key
Path
Pool
Ray
StateMachine
Timer
During
For
ForEach
Group
If
Loop
OnState
Repeat
RepeatUntil
While
EvaluateConditions
If
RepeatUntil
While