From 1885d453a49a53ca63a4667afe67e09030ceb7f1 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Thu, 5 Apr 2018 21:53:03 +0200 Subject: [PATCH] Removed #if UNITY_EDITOR from NodeGraph.cs #23 --- Scripts/Editor/NodeEditorAction.cs | 4 ++-- Scripts/Editor/NodeGraphEditor.cs | 16 ++++++++++++++++ Scripts/NodeGraph.cs | 13 ------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 7ef961c..6cea69c 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -302,7 +302,7 @@ namespace XNodeEditor { foreach (UnityEngine.Object item in Selection.objects) { if (item is XNode.Node) { XNode.Node node = item as XNode.Node; - graph.RemoveNode(node); + graphEditor.RemoveNode(node); } } } @@ -324,7 +324,7 @@ namespace XNodeEditor { if (Selection.objects[i] is XNode.Node) { XNode.Node srcNode = Selection.objects[i] as XNode.Node; if (srcNode.graph != graph) continue; // ignore nodes selected in another graph - XNode.Node newNode = graph.CopyNode(srcNode); + XNode.Node newNode = graphEditor.CopyNode(srcNode); substitutes.Add(srcNode, newNode); newNode.position = srcNode.position + new Vector2(30, 30); newNodes[i] = newNode; diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 2a8f43c..5025aaa 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -39,6 +39,22 @@ namespace XNodeEditor { return NodeEditorPreferences.GetTypeColor(type); } + /// Creates a copy of the original node in the graph + public XNode.Node CopyNode(XNode.Node original) { + XNode.Node node = target.CopyNode(original); + node.name = original.name; + AssetDatabase.AddObjectToAsset(node, target); + AssetDatabase.SaveAssets(); + return node; + } + + /// Safely remove a node and all its connections. + public void RemoveNode(XNode.Node node) { + UnityEngine.Object.DestroyImmediate(node, true); + target.RemoveNode(node); + AssetDatabase.SaveAssets(); + } + [AttributeUsage(AttributeTargets.Class)] public class CustomNodeGraphEditorAttribute : Attribute, XNodeEditor.Internal.NodeEditorBase.INodeEditorAttrib { diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs index 05b865b..09010dc 100644 --- a/Scripts/NodeGraph.cs +++ b/Scripts/NodeGraph.cs @@ -28,13 +28,6 @@ namespace XNode { public virtual Node CopyNode(Node original) { Node node = ScriptableObject.Instantiate(original); node.ClearConnections(); -#if UNITY_EDITOR - if (!Application.isPlaying) { - UnityEditor.AssetDatabase.AddObjectToAsset(node, this); - UnityEditor.AssetDatabase.SaveAssets(); - node.name = UnityEditor.ObjectNames.NicifyVariableName(node.name); - } -#endif nodes.Add(node); node.graph = this; return node; @@ -44,12 +37,6 @@ namespace XNode { /// public void RemoveNode(Node node) { node.ClearConnections(); -#if UNITY_EDITOR - if (!Application.isPlaying) { - DestroyImmediate(node, true); - UnityEditor.AssetDatabase.SaveAssets(); - } -#endif nodes.Remove(node); }