GraphEditor

Description

Graph editor allows to describe data processing algorithm as set of connected nodes, similar to Unity Visual scripting asset. This editor is not a generic visual scripting tool however, but rather focused on database data processing and relatively simple calculations.

Where it is used

# Name Description
1 Calculated fields Database fields, which calculate their values at the moment these values are requested
2 Action field Like calculated fields, but it does not return value. Instead, it can change database values, create/delete rows.
3 Graph binder Graph binder is a unit binder, which calculates the value to be injected using graph

How it works

  1. Use "Special/SetResult" node to pass the result of calculation
  2. Use "ByType" category to perform calculations for bool, string, int, float, enum and list types.
  3. Use "Database" category to perform operations on database- read/write field values, create/delete rows. Operations, changing database state, are available for "action" field only.
  4. Use "Reflection" category to read/write objects field/properties
  5. You can call another graph using "Special/Call calculated cell" and pass parameters to it using public graph variables
  6. To access current entity for calculated/action fields, use "Special/Get current entity" node.
  7. To access current Game Object for graph binder, use "Special/Get current GameObject" node.

Graph variables

Each graph can have multiple variables, which can be used during graph execution. Calculated and action fields can have a default graph (shared between all rows if not overridden)- and if this default graph has public variables- these variables can be overridden for each row. So each row can use the same shared default graph- but with different public variable values. Here is an example- lets say you have a Items table with int "value" field, which can have some additional buff and debuff values and the final value is calculated as value+buff-debuff. In this case you can have this default graph with 2 public variables:
and override variable values for each row if needed
Also, the better alternative exist in this case- you can just add "buff" and "debuff" fields to the database and use database values instead of variables.
So using public variables to customize data calculation for specific rows is advised only if it's not possible to replace variables with database fields.

Nodes reference

Folder Subfolder Nodes
ByType This folder has wrapper methods on top of C#/Unity API mostly.
bool And | Or | Or exclusive | Negate | Bool parse
enum Enum literal, Enum convert (cast enum to int),
float Float literal | Float add | Float subtract | Float multiply | Float divide | Approximately | Ceil | Ceil to int | Floor | Floor to int | Float modulo | Float parse | Pow | RoundToInt | Sqrt |
float/comparisons Float equal | Float greater | Float greater or equal | Float less | Float less or equal |
float/constants Epsilon constant | Infinity constant | NegativeInfinity constant | NaN constant | PI |
float/trigonometry Acos | Asin | Atan | Atan2 | Cos | Deg2Rad | Rad2Deg | Sin | Tan |
int Int literal | Int add | Int subtract | Int multiply | Int divide | Int modulo | Int parse
int/comparison Int equal | Int greater | Int greater or equal | Int less | Int less or equal
list List add | List addRange | List clear | List contains | List count | Create list | List get | List indexOf | List insert | List remove | List removeAt | List set |
object Cast | Change type | Equal | IsNull | NotEqual | null literal | Object to string |
string String add | IndexOf | IsNullOrEmpty | String join | String length | Split | Substring | Substring2 | ToLower | ToUpper | Trim |
Database
[MetaName] get Retrieve data from database row. Each field has its own output port. Each table has its own node.
[MetaName] set Set data from database row. Each field has its own input port. Each table has its own node. Available for "Action" field only
[MetaName] count the number of rows. Each table has its own node.
Generic/meta
Get meta Get the table object (BGMetaEntity) by index/id/name and returns table, index, id and name.
Get meta entities Returns the list of all entities for given table
Get meta fields Returns the list of all fields for given table
Count entities the number of rows for given table
Generic/field
Get field Get table field (BGField) by index/id/name and returns field, index, id and name.
Get field meta Returns the meta for given field
Generic/entity
Get entity Get entity (BGEntity) by index/id/name and returns entity, index, id and name.
Get entity meta Returns the meta for given entity
New entity Creates a new entity. Available for "Action" fields only
Delete entity Deletes an existing entity. Available for "Action" fields only
Generic/cell
Cell get value Get cell value. Accept a cell object as a input parameter
Cell get value2 Get cell value. Accept a field and entity as input parameters
Cell set value Set cell value. Accept a cell object as a input parameter. Available for "Action" fields only
Cell set value2 Set cell value. Accept a field and entity as input parameters. Available for "Action" fields only
Cell construct Construct a cell object. Accepts a field and a entity as input parameters.
Cell deconstruct Returns a entity and field for given cell
Flow
For For loop. (max iterations=10000)
While While loop. (max iterations=10000)
ForEach Invoke body action for each item in the list
Break Notify loop node to exit the loop
If Invoke "true" branch if condition==true and invoke "false" branch if condition if false
Reflection
Get field(property) get object's field or property value using C# reflection
Get static field(property) get static field or property value using C# reflection
Set field(property) set object's field or property value using C# reflection
Set static field(property) set static field or property value using C# reflection
Special
Debug print debug message to Unity console
Get current entity Returns current entity for calculated and action fields.
Get current GameObject Returns current GameObject for graph binder.
Set result This node set result value for calculated fields and graph binder
Call calculated cell This node can be used to call another calculated field from the graph. Public variables can be used to pass parameters and return results
Unity
GameObject GetComponent Accept GameObject as a parameter, returns a component by type name
GameObject GetComponents Accept GameObject as a parameter, returns the list of component by type name
Component GetGameObject Accept Component as a parameter, returns a GameObject, this component belong to
Variables
[Variable name] get Get graph variable value. Each variable has its own node.
[Variable name] set Set graph variable value. Each variable has its own node.
Localization Meta [MetaName] "Get localized value" - returns localized value. Node is added for each singleValue localization table
get locale Return current locale as string
set locale Set current locale. Available for action fields only

Graph specifications

Name Value Comment
Maximum number of nodes 255
Maximum number of ports (per node) 255
Maximum number of graph variables 255
Maximum number of iterations (for "For" and "While" nodes) 10000

Creating a custom node

Here is en example custom node for "A+B-C" expression.


using BansheeGz.BGDatabase;

[BGCalcUnitDefinition("Custom/Add remove int")]
public class AddSubtractUnit : BGCalcUnit
{
    private BGCalcValueInput a;
    private BGCalcValueInput b;
    private BGCalcValueInput c;

    public override void Definition()
    {
        a = ValueInput( "A", "a");
        b = ValueInput( "B", "b");
        c = ValueInput( "C", "c");

        ValueOutput("A+B-C", "d", GetValue);
    }

    private int GetValue(BGCalcFlowI flow)
    {
        return flow.GetValue(a) + flow.GetValue(b) - flow.GetValue(c);
    }
}

And here is an example of using this node in the graph

Use the source code package for more nodes example (search for source files, starting with BGCalcUnit prefix)