1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 09:16:01 +08:00

Minor performance improvement (cachine serialized objects)

This commit is contained in:
Thor Brigsted 2018-01-26 18:26:56 +01:00
parent 5b79757667
commit dba4cd1842

View File

@ -10,6 +10,7 @@ namespace XNodeInternal {
public class NodeEditorBase<T, A, K> where A : Attribute, NodeEditorBase<T, A, K>.INodeEditorAttrib where T : NodeEditorBase<T,A,K> where K : ScriptableObject {
/// <summary> Custom editors defined with [CustomNodeEditor] </summary>
private static Dictionary<Type, T> editors;
private static Dictionary<ScriptableObject, SerializedObject> 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<ScriptableObject, SerializedObject>();
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();