From dba4cd18429d0d2800d7391708f96da037ba8ce9 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Fri, 26 Jan 2018 18:26:56 +0100 Subject: [PATCH] Minor performance improvement (cachine serialized objects) --- Scripts/Editor/NodeEditorBase.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorBase.cs b/Scripts/Editor/NodeEditorBase.cs index 67d4833..471fea0 100644 --- a/Scripts/Editor/NodeEditorBase.cs +++ b/Scripts/Editor/NodeEditorBase.cs @@ -10,6 +10,7 @@ namespace XNodeInternal { public class NodeEditorBase where A : Attribute, NodeEditorBase.INodeEditorAttrib where T : NodeEditorBase where K : ScriptableObject { /// Custom editors defined with [CustomNodeEditor] private static Dictionary editors; + private static Dictionary serializeds; public K target; public SerializedObject serializedObject; @@ -18,10 +19,17 @@ namespace XNodeInternal { Type type = target.GetType(); T editor = GetEditor(type); editor.target = target; - editor.serializedObject = new SerializedObject(target); + editor.serializedObject = GetSerialized(target); return editor; } + private static SerializedObject GetSerialized(K target) { + if (target == null) return null; + if (serializeds == null) serializeds = new Dictionary(); + if (!serializeds.ContainsKey(target)) serializeds.Add(target, new SerializedObject(target)); + return serializeds[target]; + } + private static T GetEditor(Type type) { if (type == null) return null; if (editors == null) CacheCustomEditors();