From 0fcde9d33bdd9186619267440602556f5f047dfa Mon Sep 17 00:00:00 2001 From: Lumos Date: Wed, 1 Jan 2020 19:24:14 +0100 Subject: [PATCH] Moved method to editor and removed the global notification. --- Scripts/Editor/NodeEditor.cs | 29 +++++------------------------ Scripts/Editor/RenamePopup.cs | 6 ++++-- Scripts/Node.cs | 3 --- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 03a8ee0..edf66d6 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -129,33 +129,14 @@ namespace XNodeEditor { public void Rename(string newName) { if (newName == null || newName.Trim() == "") newName = NodeEditorUtilities.NodeDefaultName(target.GetType()); target.name = newName; - TriggerRenameNotifications(target); + OnRename(); + AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); } - /// - /// Triggers OnRename on all nodes in the graph after a node's name changes, - /// reimporting asset files for all subsequently renamed nodes. - /// - public static void TriggerRenameNotifications(XNode.Node renamedNode) { - List graphNodes = renamedNode.graph.nodes; - string[] oldNodeNames = new string[graphNodes.Count]; - // Notify all nodes, allow them to further change names accordingly - for (int i = 0; i < graphNodes.Count; i++) { - XNode.Node node = graphNodes[i]; - oldNodeNames[i] = node.name; - node.OnRename(renamedNode); - } - - // After all user-driven modifications have been resolved, update all assets whose node names have changed - // (And always reimport the node which got renamed in the first place) - for (int i = 0; i < graphNodes.Count; i++) { - if (graphNodes[i] == renamedNode || graphNodes[i].name != oldNodeNames[i]) { - AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graphNodes[i])); - } - } - } + /// Called after this node's name has changed. + public virtual void OnRename() { } + - [AttributeUsage(AttributeTargets.Class)] public class CustomNodeEditorAttribute : Attribute, XNodeEditor.Internal.NodeEditorBase.INodeEditorAttrib { diff --git a/Scripts/Editor/RenamePopup.cs b/Scripts/Editor/RenamePopup.cs index 72d76fa..f245d4e 100644 --- a/Scripts/Editor/RenamePopup.cs +++ b/Scripts/Editor/RenamePopup.cs @@ -49,7 +49,8 @@ namespace XNodeEditor { if (input == null || input.Trim() == "") { if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) { target.name = NodeEditorUtilities.NodeDefaultName(target.GetType()); - NodeEditor.TriggerRenameNotifications((XNode.Node)target); + NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename(); + AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); Close(); target.TriggerOnValidate(); } @@ -58,7 +59,8 @@ namespace XNodeEditor { else { if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) { target.name = input; - NodeEditor.TriggerRenameNotifications((XNode.Node)target); + NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename(); + AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); Close(); target.TriggerOnValidate(); } diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 6398c1e..a07679a 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -254,9 +254,6 @@ namespace XNode { /// Called after a connection is removed from this port /// Output or Input public virtual void OnRemoveConnection(NodePort port) { } - - /// Called after a node's name has changed. - public virtual void OnRename(Node node) { } /// Disconnect everything from this node public void ClearConnections() {