From e04b4fc9894c8a3a077c6fd42a9b39a4914c5f02 Mon Sep 17 00:00:00 2001 From: Icarus <1375400884@qq.com> Date: Sun, 1 Dec 2019 21:11:11 +0800 Subject: [PATCH] !W(Node Editor GUILayout) DynamicPortList Add `OnAdd` Action --- Scripts/Editor/NodeEditorGUILayout.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index c52a128..0a09cc4 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -306,7 +306,7 @@ namespace XNodeEditor { public static void DynamicPortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None,Type inputTypeConstraintBaseType = null, - Action onCreation = null) { + Action onCreation = null,Action onAdd = null) { XNode.Node node = serializedObject.targetObject as XNode.Node; var indexedPorts = io == NodePort.IO.Input ? node.DynamicInputs : node.DynamicOutputs; @@ -323,7 +323,7 @@ namespace XNodeEditor { if (list == null) { SerializedProperty arrayData = serializedObject.FindProperty(fieldName); list = CreateReorderableList(fieldName, dynamicPorts, arrayData, type, serializedObject, - io, connectionType, typeConstraint, inputTypeConstraintBaseType); + io, connectionType, typeConstraint, inputTypeConstraintBaseType,onAdd); onCreation?.Invoke(list); if (reorderableListCache.TryGetValue(serializedObject.targetObject, out rlc)) rlc.Add(fieldName, list); else reorderableListCache.Add(serializedObject.targetObject, new Dictionary() { { fieldName, list } }); @@ -334,7 +334,7 @@ namespace XNodeEditor { private static ReorderableList CreateReorderableList(string fieldName, List dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, - Type inputTypeConstraintBaseType) { + Type inputTypeConstraintBaseType,Action onAdd) { bool hasArrayData = arrayData != null && arrayData.isArray; XNode.Node node = serializedObject.targetObject as XNode.Node; ReorderableList list = new ReorderableList(dynamicPorts, null, true, true, true, true); @@ -421,6 +421,8 @@ namespace XNodeEditor { arrayData.InsertArrayElementAtIndex(arrayData.arraySize); } serializedObject.ApplyModifiedProperties(); + + onAdd?.Invoke(newName); }; list.onRemoveCallback = (ReorderableList rl) =>