Creating full flow nodes can be a bit harder to understand, but you get full access to everything and can create any type of node you want, like for example new Events, Flow Controllers, or anything else.
Let’s take an example of re-creating a FlowController node, the “SwitchBool”, which practically is an if-then-else statement. To do so, create a class and derive from “FlowControlNode”, then you must override the RegisterPorts method and register the ports within.
Registering the ports is done by using the following methods:
FlowInput : AddFlowInput(string name, FlowHandler pointer)
name: The name of the port.
pointer: A delegate that will be called when this flow input is called.
FlowOutput: AddFlowOutput(string name)
name: The name of the port.
To execute the port, you have to call, Call() on the FlowOutput object returned, along with the current Flow object received.
ValueInput<T> : AddValueInput<T>(string name)
name: The name of the port.
To get the value connected to the port, you simply do so by calling the .value property of the object returned.
ValueOutput<T> : AddValueOutput<T>(string name, ValueHandler<T> getter)
name: The name of the port.
getter: A delegate that will be called to get the value of type T.
In practice, it’s easier than it sounds…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using ParadoxNotion.Design; namespace FlowCanvas.Nodes{ [Name("Switch Condition")] [Category("Flow Controllers/Switchers")] [Description("Branch the Flow based on a conditional boolean value")] public class SwitchBool : FlowControlNode { protected override void RegisterPorts(){ var condition = AddValueInput<bool>("Condition"); var trueOut = AddFlowOutput("True"); var falseOut = AddFlowOutput("False"); AddFlowInput("In", (f)=> f.Call( condition.value? trueOut : falseOut ) ); } } } |
As you see above, there are a number of attributes you can use for specifying the name if it needs to be different than the class name, as well as attributes for the node’s category and help description.