-
-
Notifications
You must be signed in to change notification settings - Fork 603
Nodes
Any class deriving from Node
is automatically registered as a node in the graph editor, and can be added via the right-click menu.
A simple node with a single input and a single output can look like this:
public class SimpleNode : Node {
[Input] public float value;
[Output] public float result;
}
When another node asks for the output of this node, the method object GetValue(NodePort port);
is called. You need to override it in order to have your node return something sensible. In this example, we will just return the input value.
// Returns value + 1
public class SimpleNode : Node {
[Input] public float value;
[Output] public float result;
public override object GetValue(NodePort port) {
// Check which output is being requested.
// In this node, there aren't any other outputs than "result".
if (port.fieldName == "result") {
// Return input value + 1
return GetInputValue<float>("value", this.value) + 1;
}
}
}
By default, the context menu path will be based upon namespace and class name. If you wish to change this, you can use the [CreateNodeMenu] class attribute. Simply add it to your class and supply it with your desired path.
[CreateNodeMenu("MyMathNodes/Subtraction")]
Nodes types can be tinted for easier grouping and overview. To do this, simply add a [NodeTint] attribute to your node class, and supply it with either a hex color string, or 3 floats representing rgb.
[NodeTint("#ffaaaa")]
[NodeTint(1.0f, 0.8f, 0.8f)]