-
-
Notifications
You must be signed in to change notification settings - Fork 612
Node.[Input Output]
Thor Brigsted edited this page Jan 17, 2019
·
4 revisions
public [Input(ShowBackingValue backingValue, ConnectionType connectionType, bool instancePortList = false)];
public [Output(ShowBackingValue backingValue, ConnectionType connectionType, bool instancePortList = false)];
Parameters | Summary |
---|---|
backingValue | When to show the field inspector associated with this NodePort. |
connectionType | Should we allow multiple connections? |
instancePortList | Display a reoderable list of ports, optionally using array data as backing values |
Assign an input or output port to a public or private serialized field.
public class ExampleNode : Node{
[Input] public float a;
[Output] public float b;
}
If you need a dynamic list of ports instead of a single port, consider setting instancePortList
to true
eg. [Input(instancePortList = true)]
This will transform the field into a reorderable list of ports with add and remove buttons. If the field is an array or list type, a value will also be displayed for each element.
You may want to customize the way the list is drawn. You can do this by modifying the list delegates after the list is created, by manually drawing the list in a custom NodeEditor with the method NodeEditorGUILayout.InstancePortList
which takes an Action<ReorderableList> onCreation
parameter
public class MyNodeEditor : NodeEditor {
public override void OnBodyGUI() {
// Draw GUI
NodeEditorGUILayout.InstancePortList("myFloatList", typeof(float), serializedObject, NodePort.IO.Input, Node.ConnectionType.Override, OnCreateReorderableList);
}
void OnCreateReorderableList(ReorderableList list) {
// Override drawHeaderCallback to display node's name instead
list.drawHeaderCallback = (Rect rect) => {
string title = serializedObject.targetObject;
EditorGUI.Label(rect, title);
};
}
}