mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Minor performance improvement (cachine serialized objects)
This commit is contained in:
parent
5b79757667
commit
dba4cd1842
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user