@@ -130,7 +130,7 @@ private void OnClickToAddNewItem(Rect buttonRect, ReorderableList list)
130130 private float GetCollectionItemHeight ( int index )
131131 {
132132 if ( itemHidden == null || itemHidden . Length == 0 || itemHidden [ index ] || index > itemHidden . Length - 1 )
133- return EditorGUIUtility . singleLineHeight + EditorGUIUtility . standardVerticalSpacing ;
133+ return 0 ;
134134
135135 return Mathf . Max (
136136 heights [ index ] ,
@@ -169,6 +169,9 @@ private void DrawCollectionItemAtIndex(Rect rect, int index, bool isActive, bool
169169 if ( Event . current . alt )
170170 SetAllExpanded ( false ) ;
171171 }
172+
173+ if ( wasExpanded != collectionItemSerializedProperty . isExpanded )
174+ itemIndexToRect . Clear ( ) ;
172175
173176 using ( EditorGUI . ChangeCheckScope changeCheck = new EditorGUI . ChangeCheckScope ( ) )
174177 {
@@ -208,52 +211,91 @@ private void DrawCollectionItemAtIndex(Rect rect, int index, bool isActive, bool
208211
209212 if ( collectionItemSerializedProperty . isExpanded )
210213 {
211- rect . y += EditorGUIUtility . standardVerticalSpacing ;
214+ rect . y += EditorGUIUtility . standardVerticalSpacing ;
215+
216+ if ( SOCSettings . Instance . ShouldDrawUsingCustomEditor ( collection ) )
217+ DrawCustomEditor ( ref rect , index , collectionItemSerializedProperty ) ;
218+ else
219+ DrawProperties ( ref rect , index , collectionItemSerializedProperty ) ;
220+ }
212221
213- if ( itemIndexToRect . TryGetValue ( index , out Rect actualRect ) && reorderableListYPosition . HasValue )
222+ CheckForContextInputOnItem ( collectionItemSerializedProperty , index , originY , rect ) ;
223+
224+ heights [ index ] = rect . y - originY ;
225+ }
226+
227+ private void DrawProperties ( ref Rect rect , int index , SerializedProperty collectionItemSerializedProperty )
228+ {
229+ EditorGUI . indentLevel ++ ;
230+
231+ SerializedObject collectionItemSerializedObject = new SerializedObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
232+ SerializedProperty iterator = collectionItemSerializedObject . GetIterator ( ) ;
233+
234+ using ( EditorGUI . ChangeCheckScope changeCheck = new EditorGUI . ChangeCheckScope ( ) )
235+ {
236+ for ( bool enterChildren = true ; iterator . NextVisible ( enterChildren ) ; enterChildren = false )
214237 {
215- actualRect . y = rect . y + reorderableListYPosition . Value + reorderableList . headerHeight ;
238+ bool guiEnabled = GUI . enabled ;
239+ if ( iterator . displayName . Equals ( "Script" ) )
240+ GUI . enabled = false ;
216241
217- // Have to indent the rect here because otherwise it overlaps with the drag handle
218- EditorGUI . indentLevel ++ ;
219- actualRect = EditorGUI . IndentedRect ( actualRect ) ;
220- EditorGUI . indentLevel -- ;
242+ EditorGUI . PropertyField ( rect , iterator , true ) ;
243+ GUI . enabled = guiEnabled ;
244+
245+ rect . y += EditorGUI . GetPropertyHeight ( iterator , true ) +
246+ EditorGUIUtility . standardVerticalSpacing ;
247+ }
221248
222- GUILayout . BeginArea ( actualRect ) ;
223- EditorGUI . indentLevel ++ ;
249+ if ( changeCheck . changed )
250+ iterator . serializedObject . ApplyModifiedProperties ( ) ;
251+ }
252+ EditorGUI . indentLevel -- ;
253+ }
224254
225- Editor editor = EditorCache . GetOrCreateEditorForObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
226- editor . OnInspectorGUI ( ) ;
255+ private void DrawCustomEditor ( ref Rect rect , int index , SerializedProperty collectionItemSerializedProperty )
256+ {
257+ Editor editor = EditorCache . GetOrCreateEditorForObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
227258
228- EditorGUI . indentLevel -- ;
229- GUILayout . EndArea ( ) ;
259+ if ( itemIndexToRect . TryGetValue ( index , out Rect actualRect ) && reorderableListYPosition . HasValue )
260+ {
261+ actualRect . y = rect . y + reorderableListYPosition . Value + reorderableList . headerHeight ;
262+
263+ // Have to indent the rect here because otherwise it overlaps with the drag handle
264+ EditorGUI . indentLevel ++ ;
265+ actualRect = EditorGUI . IndentedRect ( actualRect ) ;
266+ EditorGUI . indentLevel -- ;
267+
268+ GUILayout . BeginArea ( actualRect ) ;
269+ EditorGUI . indentLevel ++ ;
230270
271+ EditorGUI . BeginChangeCheck ( ) ;
272+ editor . OnInspectorGUI ( ) ;
273+
274+ EditorGUI . indentLevel -- ;
275+ GUILayout . EndArea ( ) ;
276+
277+ if ( EditorGUI . EndChangeCheck ( ) )
278+ {
231279 collectionItemSerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
232- rect . y += actualRect . height ;
233280 }
234- else
235- {
236- Rect verticalRect = EditorGUILayout . BeginVertical ( ) ;
237-
238- Editor editor = EditorCache . GetOrCreateEditorForObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
239- editor . OnInspectorGUI ( ) ;
240281
241- EditorGUILayout . EndVertical ( ) ;
282+ rect . y += actualRect . height ;
283+ }
284+ else
285+ {
286+ Rect verticalRect = EditorGUILayout . BeginVertical ( ) ;
242287
243- if ( Event . current . type == EventType . Repaint )
244- {
245- itemIndexToRect [ index ] = verticalRect ;
246- }
288+ editor . OnInspectorGUI ( ) ;
289+
290+ EditorGUILayout . EndVertical ( ) ;
291+
292+ if ( Event . current . type == EventType . Repaint )
293+ {
294+ itemIndexToRect [ index ] = verticalRect ;
247295 }
248296 }
249-
250- CheckForContextInputOnItem ( collectionItemSerializedProperty , index , originY , rect ) ;
251-
252- heights [ index ] = rect . y - originY ;
253297 }
254298
255-
256-
257299 private void SetAllExpanded ( bool expanded )
258300 {
259301 for ( int i = 0 ; i < reorderableList . count ; i ++ )
@@ -670,6 +712,8 @@ private void DrawSettings()
670712 DrawUseBaseClassToggle ( ) ;
671713 DrawGeneratedFileName ( ) ;
672714 DrawGeneratedFileNamespace ( ) ;
715+ DrawDrawOptions ( ) ;
716+
673717 GUILayout . Space ( 10 ) ;
674718 DrawDeleteCollection ( ) ;
675719
@@ -678,6 +722,16 @@ private void DrawSettings()
678722 }
679723 }
680724
725+ private void DrawDrawOptions ( )
726+ {
727+ using EditorGUI . ChangeCheckScope changeCheck = new EditorGUI . ChangeCheckScope ( ) ;
728+ bool drawUsingCustomEditor = EditorGUILayout . Toggle ( "Use Custom Editor" , SOCSettings . Instance . ShouldDrawUsingCustomEditor ( collection ) ) ;
729+ if ( changeCheck . changed )
730+ {
731+ SOCSettings . Instance . SetUseCustomEditor ( collection , drawUsingCustomEditor ) ;
732+ }
733+ }
734+
681735 private void DrawDeleteCollection ( )
682736 {
683737 Color backgroundColor = GUI . backgroundColor ;
0 commit comments