-
-
Notifications
You must be signed in to change notification settings - Fork 599
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.
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.
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] as NewNode) return nodes[i] as NewNode;
}
return null;
}
}
Graphs support the [ContextMenu] attribute. Simply add [ContextMenu] to a non-static method and it will show up when you right-click anywhere on the grid. Select it to execute the method. You can read more about it here