Creating Simplex Nodes is the easiest and most direct way of creating custom nodes for FlowCanvas, but they have limitations (in which case you might want to check out “Creating Full Nodes” later). To do so, you need to derive from one of the available Simplex node base types.
Callable Action Nodes, are meant to create actions requiring a flow signal to be called. They have 1 Flow input, 1 Flow output, up to 5 Value input parameters and no Value outputs at all. Simply put, you derive the generic CallableActionNode class where the generic arguments represent the value input parameters of your node and then you override the Invoke void method, which has a number of parameters equal and of same type as the generic arguments you declared. For example.
1 2 3 4 5 6 |
[Category("Actions/Utility")] public class LogValue : CallableActionNode<object>{ public override void Invoke(object obj){ Debug.Log(obj); } } |
Callable Function Nodes, are similar to the Callable Action above, but they always return 1 Value output. The process is very similar to before, but in this case the first generic argument represents the type of the return value and the Invoke method that you will override will need to return that type declared. For example.
1 2 3 4 5 6 |
[Category("Examples")] public class FindTransform : CallableFunctionNode<Transform, Transform, string>{ public override Transform Invoke(Transform root, string name){ return root != null? root.Find(name) : null; } } |
Latent Action Nodes are similar to CallableAction Nodes before, but in this case the Invoke method is a IEnumerator and is called as a coroutine. As such, you need to treat it as a coroutine. For example.
1 2 3 4 5 6 7 8 9 10 |
[Category("Actions/Utility")] public class Wait : LatentActionNode<float>{ public override IEnumerator Invoke(float time){ var timer = time; while (timer > 0){ timer -= Time.deltaTime; yield return null; } } } |
Pure Function Nodes, are meant for nodes that do not need any flow signal to use, but instead they simply return a value when they are requested through the single Value output they have. The first generic argument is the return type of the node and the Invoke method you need to override, while the rest of the generic arguments are the value input parameters of the function to be used. For example.
1 2 3 4 5 6 7 |
[Category("Functions/Math/Floats")] [Name("!=")] public class FloatNotEqual : PureFunctionNode<bool, float, float>{ public override bool Invoke(float a, float b){ return a != b; } } |
© Paradox Notion 2015-2024. All rights reserved.