@@ -28,6 +28,8 @@ public sealed class CollectionCustomEditor : Editor
2828 private ReorderableList reorderableList ;
2929 private SerializedProperty itemsSerializedProperty ;
3030 private int lastCheckedForValidItemsArraySize ;
31+ private readonly Dictionary < int , Rect > itemIndexToRect = new ( ) ;
32+ private float ? reorderableListYPosition ;
3133
3234 private static bool IsWaitingForNewTypeBeCreated
3335 {
@@ -185,39 +187,50 @@ private void DrawCollectionItemAtIndex(Rect rect, int index, bool isActive, bool
185187 {
186188 rect . y += EditorGUIUtility . standardVerticalSpacing ;
187189
188- SerializedObject collectionItemSerializedObject = new SerializedObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
189-
190- EditorGUI . indentLevel ++ ;
191-
192- SerializedProperty iterator = collectionItemSerializedObject . GetIterator ( ) ;
193-
194- using ( EditorGUI . ChangeCheckScope changeCheck = new EditorGUI . ChangeCheckScope ( ) )
190+ if ( itemIndexToRect . TryGetValue ( index , out Rect actualRect ) && reorderableListYPosition . HasValue )
195191 {
196- for ( bool enterChildren = true ; iterator . NextVisible ( enterChildren ) ; enterChildren = false )
197- {
198- bool guiEnabled = GUI . enabled ;
199- if ( iterator . displayName . Equals ( "Script" ) )
200- GUI . enabled = false ;
192+ actualRect . y = rect . y + reorderableListYPosition . Value + reorderableList . headerHeight ;
193+
194+ // Have to indent the rect here because otherwise it overlaps with the drag handle
195+ EditorGUI . indentLevel ++ ;
196+ actualRect = EditorGUI . IndentedRect ( actualRect ) ;
197+ EditorGUI . indentLevel -- ;
198+
199+ GUILayout . BeginArea ( actualRect ) ;
200+ EditorGUI . indentLevel ++ ;
201201
202- EditorGUI . PropertyField ( rect , iterator , true ) ;
203- GUI . enabled = guiEnabled ;
202+ Editor editor = EditorCache . GetOrCreateEditorForObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
203+ editor . OnInspectorGUI ( ) ;
204204
205- rect . y += EditorGUI . GetPropertyHeight ( iterator , true ) +
206- EditorGUIUtility . standardVerticalSpacing ;
207- }
205+ EditorGUI . indentLevel -- ;
206+ GUILayout . EndArea ( ) ;
208207
209- if ( changeCheck . changed )
210- iterator . serializedObject . ApplyModifiedProperties ( ) ;
208+ collectionItemSerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
209+ rect . y += actualRect . height ;
211210 }
211+ else
212+ {
213+ Rect verticalRect = EditorGUILayout . BeginVertical ( ) ;
214+
215+ Editor editor = EditorCache . GetOrCreateEditorForObject ( collectionItemSerializedProperty . objectReferenceValue ) ;
216+ editor . OnInspectorGUI ( ) ;
212217
213- EditorGUI . indentLevel -- ;
218+ EditorGUILayout . EndVertical ( ) ;
219+
220+ if ( Event . current . type == EventType . Repaint )
221+ {
222+ itemIndexToRect [ index ] = verticalRect ;
223+ }
224+ }
214225 }
215226
216227 CheckForContextInputOnItem ( collectionItemSerializedProperty , index , originY , rect ) ;
217-
228+
218229 heights [ index ] = rect . y - originY ;
219230 }
220231
232+
233+
221234 private void SetAllExpanded ( bool expanded )
222235 {
223236 for ( int i = 0 ; i < reorderableList . count ; i ++ )
@@ -344,6 +357,10 @@ public override void OnInspectorGUI()
344357 DrawSearchField ( ) ;
345358 DrawSynchronizeButton ( ) ;
346359 reorderableList . DoLayoutList ( ) ;
360+ if ( Event . current . type == EventType . Repaint )
361+ {
362+ reorderableListYPosition = GUILayoutUtility . GetLastRect ( ) . y ;
363+ }
347364 DrawBottomMenu ( ) ;
348365 }
349366 DrawSettings ( ) ;
0 commit comments