-
-
Notifications
You must be signed in to change notification settings - Fork 600
Graphs
class NodeGraph : ScriptableObject
Every xNode project starts with the creation of a graph. The graph contains a list of nodes, and what you decide to do with those nodes is up to you.
You can customize the look of your graphs through a graph editor
Your graph should act as the topmost entry point for your nodes. Depending on your needs, you can implement methods such as GetFirstNode, GetRootNode, GetResult, UpdateAI etc. inside your graph. It can also be used to contain variables that all your nodes rely on, perhaps a currentNode field for a state machine.
Graph classes are extremely simple. All they have to do is derive from NodeGraph
. Ideally you also add the [CreateAssetMenu]
attribute so that you are able to create the graph through the native asset creation menu in Unity.
[CreateAssetMenu]
public class SimpleGraph : NodeGraph { }
In this class you can define you own entry points to the graph. For example a method StartGraph()
that loops through all nodes and calls Trigger()
on those of a certain type.
Nodes are accessible through the nodes
variable, and looping through it is your main entrance point to your graph.
[CreateAssetMenu]
public class SimpleGraph : NodeGraph {
public RootNode GetRootNode() {
for (int i = 0; i < nodes.Count; i++) {
if (nodes[i] is NewNode) return nodes[i] as NewNode;
}
return null;
}
}