-
-
Notifications
You must be signed in to change notification settings - Fork 599
NodeEditorGUILayout.InstancePortList
Thor Brigsted edited this page Sep 5, 2018
·
3 revisions
Draw an editable list of instance ports. Port names are named as "[fieldName] [index]"
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple);
Parameters | Summary |
---|---|
fieldName | Base fieldName of the instance ports. If points to the field name of a list, the list will be used as backing values. |
type | Instance NodePort value type. |
serializedObject | The serializedObject of the node. |
io | Whether this list creates inputs or outputs |
connectionType | Connection type of added instance ports |
// ExampleNode.cs
public class ExampleNode : Node {
// We will display the list through custom editor, so hide it from the default editor
[HideInInspector] public List<int> choices;
public override object GetValue(NodePort port) {
// The instance ports created this way will use the list fieldName and index number, separated by space
if (port.fieldName.StartsWith("choices ")) {
int index = int.Parse(port.fieldName.Split(' ')[1]);
return choices[index];
}
return null;
}
}
// Editor/ExampleNodeEditor.cs
[CustomNodeEditor(typeof(ExampleNode))]
public class ExampleNodeEditor : NodeEditor {
public override void OnBodyGUI() {
// Draw default editor first
base.OnBodyGUI();
// Draw list with instance ports
NodeEditorGUILayout.InstancePortList("choices", typeof(int), serializedObject, NodePort.IO.Output);
}
}
See also: AddInstancePort, RemoveInstancePort