SubjectNerd-Unity / ReorderableInspector

Automatic reorderable lists for Unity game engine components
MIT License
485 stars 47 forks source link

Unity editor become very slow if reorder List has large struct and large array elements. #12

Open LoS-Light opened 5 years ago

LoS-Light commented 5 years ago

Unity editor is very slow if reorder List has large struct and large array elements.

mages-gamedev commented 5 years ago

I also noticed the same thing when these structs and array elements contain ScriptableObjects.

Here are several tests I've done:

  1. ScriptableObject containing classes which contain ScriptableObject fields will lag if both #LIST_ALL_ARRAYS and #EDIT_ALL_SCRIPTABLES are uncommented
  2. ScriptableObject containing classes which contain ScriptableObject fields will not lag if only #LIST_ALL_ARRAYS is uncommented

I've also noticed that if a ScriptableObject contains classes which contain ScriptableObjects, the classes' ScriptableObjects are not editable.

Solution I made a new PropertyAttribute called NonEditScriptableProperty and added the new header into any child ScriptableObject fields of a ScriptableObject

public class NonEditScriptableAttribute : PropertyAttribute { }

And edited this in ReorderableArrayInspector.cs starting from line 367:

#if EDIT_ALL_SCRIPTABLES
    bool makeEditable = !iterProp.HasAttribute<NonEditScriptableAttribute>();
#else
    bool makeEditable = iterProp.HasAttribute<EditScriptableAttribute>();
#endif

The logic in play here is to set makeEditable to false if a field has the NonEditScriptable attribute. Add this attribute to any inner ScriptableObjects and you should notice that the lag is gone. I have not tested on large Lists of ScriptableObjects.

Example:

[SubjectNerd.Utilities.NonEditScriptable]
[Tooltip("A un-editable ScriptableObject")]
public MyScriptableObject myScriptableObject;

Hope this helps! @LoS-Light @ChemiKhazi

LoS-Light commented 5 years ago

Thank you very much.

mages-gamedev notifications@github.com於 2019年2月20日 週三,22:48寫道:

I also noticed the same thing.

Here are several tests I've done:

  1. ScriptableObject containing other child ScriptableObject fields will lag if both #LIST_ALL_ARRAYS and #EDIT_ALL_SCRIPTABLES are uncommented
  2. ScriptableObject containing other child ScriptableObject fields will not lag if only #LIST_ALL_ARRAYS is uncommented

Solution I made a new PropertyAttribute called NonEditScriptableProperty and added the new header into any child ScriptableObject fields of a ScriptableObject

public class NonEditScriptableAttribute : PropertyAttribute { }

And edited this in ReorderableArrayInspector.cs starting from line 367:

if EDIT_ALL_SCRIPTABLES

bool makeEditable = !iterProp.HasAttribute<NonEditScriptableAttribute>();

else

bool makeEditable = iterProp.HasAttribute<EditScriptableAttribute>();

endif

Example:

[SubjectNerd.Utilities.NonEditScriptable] [Tooltip("A un-editable ScriptableObject")]public MyScriptableObject myScriptableObject;

Hope this helps! @LoS-Light https://github.com/LoS-Light @ChemiKhazi https://github.com/ChemiKhazi

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SubjectNerd-Unity/ReorderableInspector/issues/12#issuecomment-465607590, or mute the thread https://github.com/notifications/unsubscribe-auth/AZKcNcPnf_PC89DKn25G34DntR23pclQks5vPWBIgaJpZM4Z0w74 .