@@ -30,7 +30,9 @@ public class CollectionCustomEditor : BaseEditor<CollectionCustomEditor>
3030 protected int lastCheckedForValidItemsArraySize ;
3131 private readonly Dictionary < int , Rect > itemIndexToRect = new ( ) ;
3232 private float ? reorderableListYPosition ;
33+ private Dictionary < Object , SerializedObject > collectionItemSerializedObjectCache = new ( ) ;
3334
35+ protected virtual bool CanBeReorderable => true ;
3436 protected virtual bool DisplayAddButton => true ;
3537 protected virtual bool DisplayRemoveButton => true ;
3638 protected virtual bool AllowCustomTypeCreation => true ;
@@ -61,7 +63,7 @@ protected virtual void OnEnable()
6163
6264 private void CreateReorderableList ( )
6365 {
64- reorderableList = new ReorderableList ( serializedObject , itemsSerializedProperty , true , true , DisplayAddButton , DisplayRemoveButton ) ;
66+ reorderableList = new ReorderableList ( serializedObject , itemsSerializedProperty , CanBeReorderable , true , DisplayAddButton , DisplayRemoveButton ) ;
6567 reorderableList . drawElementCallback += DrawCollectionItemAtIndex ;
6668 reorderableList . elementHeightCallback += GetCollectionItemHeight ;
6769 reorderableList . onAddDropdownCallback += OnClickToAddNewItem ;
@@ -141,7 +143,7 @@ private float GetCollectionItemHeight(int index)
141143 private void DrawCollectionItemAtIndex ( Rect rect , int index , bool isActive , bool isFocused )
142144 {
143145 SerializedProperty collectionItemSerializedProperty = reorderableList . serializedProperty . GetArrayElementAtIndex ( index ) ;
144-
146+
145147 if ( itemHidden [ index ] || collectionItemSerializedProperty . objectReferenceValue == null )
146148 return ;
147149
@@ -212,7 +214,7 @@ private void DrawCollectionItemAtIndex(Rect rect, int index, bool isActive, bool
212214 if ( collectionItemSerializedProperty . isExpanded )
213215 {
214216 rect . y += EditorGUIUtility . standardVerticalSpacing ;
215-
217+
216218 if ( SOCSettings . Instance . ShouldDrawUsingCustomEditor ( collection ) )
217219 DrawCustomEditor ( ref rect , index , collectionItemSerializedProperty ) ;
218220 else
@@ -228,11 +230,18 @@ private void DrawProperties(ref Rect rect, int index, SerializedProperty collect
228230 {
229231 EditorGUI . indentLevel ++ ;
230232
231- SerializedObject collectionItemSerializedObject = new SerializedObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
232- SerializedProperty iterator = collectionItemSerializedObject . GetIterator ( ) ;
233+ if ( ! collectionItemSerializedObjectCache . TryGetValue ( collectionItemSerializedProperty . objectReferenceValue , out SerializedObject serializedObject ) )
234+ {
235+ serializedObject = new SerializedObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
236+ collectionItemSerializedObjectCache . Add ( collectionItemSerializedProperty . objectReferenceValue , serializedObject ) ;
237+ }
233238
239+ serializedObject . Update ( ) ;
240+
234241 using ( EditorGUI . ChangeCheckScope changeCheck = new EditorGUI . ChangeCheckScope ( ) )
235242 {
243+ SerializedProperty iterator = serializedObject . GetIterator ( ) ;
244+
236245 for ( bool enterChildren = true ; iterator . NextVisible ( enterChildren ) ; enterChildren = false )
237246 {
238247 bool guiEnabled = GUI . enabled ;
@@ -241,14 +250,15 @@ private void DrawProperties(ref Rect rect, int index, SerializedProperty collect
241250
242251 EditorGUI . PropertyField ( rect , iterator , true ) ;
243252 GUI . enabled = guiEnabled ;
244-
253+
245254 rect . y += EditorGUI . GetPropertyHeight ( iterator , true ) +
246255 EditorGUIUtility . standardVerticalSpacing ;
247256 }
248-
257+
249258 if ( changeCheck . changed )
250- iterator . serializedObject . ApplyModifiedProperties ( ) ;
259+ serializedObject . ApplyModifiedProperties ( ) ;
251260 }
261+
252262 EditorGUI . indentLevel -- ;
253263 }
254264
@@ -268,16 +278,16 @@ private void DrawCustomEditor(ref Rect rect, int index, SerializedProperty colle
268278 GUILayout . BeginArea ( actualRect ) ;
269279 EditorGUI . indentLevel ++ ;
270280
271- EditorGUI . BeginChangeCheck ( ) ;
281+ // EditorGUI.BeginChangeCheck();
272282 editor . OnInspectorGUI ( ) ;
273283
274284 EditorGUI . indentLevel -- ;
275285 GUILayout . EndArea ( ) ;
276286
277- if ( EditorGUI . EndChangeCheck ( ) )
278- {
279- collectionItemSerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
280- }
287+ // if (EditorGUI.EndChangeCheck())
288+ // {
289+ // collectionItemSerializedProperty.serializedObject.ApplyModifiedProperties();
290+ // }
281291
282292 rect . y += actualRect . height ;
283293 }
@@ -415,6 +425,7 @@ private void DuplicateItem(int index)
415425 public override void OnInspectorGUI ( )
416426 {
417427 base . BeginInspector ( ) ;
428+ EditorGUI . BeginChangeCheck ( ) ;
418429 HideProperties ( ) ;
419430
420431 ValidateCollectionItems ( ) ;
@@ -434,6 +445,8 @@ public override void OnInspectorGUI()
434445 DrawSettings ( ) ;
435446 CheckForKeyboardShortcuts ( ) ;
436447 DrawRemainingPropertiesInInspector ( ) ;
448+ if ( EditorGUI . EndChangeCheck ( ) )
449+ serializedObject . ApplyModifiedProperties ( ) ;
437450 }
438451
439452 private void CheckHeightsAndHiddenArraySizes ( )
@@ -449,12 +462,16 @@ private void DrawSynchronizeButton()
449462 {
450463 if ( GUILayout . Button ( "Synchronize Assets" ) )
451464 {
452- collection . RefreshCollection ( ) ;
453- serializedObject . Update ( ) ;
454- CheckHeightsAndHiddenArraySizes ( ) ;
465+ SynchronizeAssets ( ) ;
455466 }
456467 }
457468
469+ protected virtual void SynchronizeAssets ( )
470+ {
471+ collection . RefreshCollection ( ) ;
472+ CheckHeightsAndHiddenArraySizes ( ) ;
473+ }
474+
458475 private void CheckForKeyboardShortcuts ( )
459476 {
460477 if ( reorderableList . index == - 1 )
0 commit comments