From ab158dab7c9da0eea6dc9ec7f47454702ed2f895 Mon Sep 17 00:00:00 2001 From: Oscar Toomey Date: Fri, 10 Apr 2020 21:35:54 +0100 Subject: [PATCH] Implemented #242 - Added NodeEditor.OnEnable() --- Scripts/Editor/NodeEditorBase.cs | 15 +++++++++++++++ Scripts/Editor/NodeEditorWindow.cs | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Scripts/Editor/NodeEditorBase.cs b/Scripts/Editor/NodeEditorBase.cs index 1fc28c7..117e017 100644 --- a/Scripts/Editor/NodeEditorBase.cs +++ b/Scripts/Editor/NodeEditorBase.cs @@ -49,8 +49,14 @@ namespace XNodeEditor.Internal { editor.target = target; editor.serializedObject = new SerializedObject(target); editor.window = window; + + // OnCreate is obsolete - use OnEnable instead +#pragma warning disable 0618 editor.OnCreate(); +#pragma warning restore 0618 + editors.Add(target, editor); + editor.OnEnable(); } if (editor.target == null) editor.target = target; if (editor.window != window) editor.window = window; @@ -81,9 +87,18 @@ namespace XNodeEditor.Internal { } } + /// Clears stored editors. Called when a new graph opens. Ensures that NodeEditor.OnEnable is called as expected. + public static void ClearCachedEditors() { + editors = new Dictionary(); + } + /// Called on creation, after references have been set + [Obsolete("OnCreate() is deprecated, please use OnEnable() instead.")] public virtual void OnCreate() { } + /// Called when a graph containing the node is opened + public virtual void OnEnable() { } + public interface INodeEditorAttrib { Type GetInspectedType(); } diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index 4fc1136..80e92a8 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -55,6 +55,7 @@ namespace XNodeEditor { } private void OnEnable() { + NodeEditor.ClearCachedEditors(); // Reload portConnectionPoints if there are any int length = _references.Length; if (length == _rects.Length) { @@ -193,6 +194,7 @@ namespace XNodeEditor { NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow; w.wantsMouseMove = true; w.graph = graph; + NodeEditor.ClearCachedEditors(); return w; }