@@ -13,10 +13,9 @@ namespace RuntimeUnityEditor.Core.Inspector
1313 /// </summary>
1414 public sealed partial class Inspector : Window < Inspector >
1515 {
16- private const int InspectorRecordHeight = 25 ;
16+ internal const int InspectorRecordInitialHeight = 25 ;
1717 private readonly GUILayoutOption [ ] _inspectorTypeWidth = { GUILayout . Width ( 170 ) , GUILayout . MaxWidth ( 170 ) } ;
1818 private readonly GUILayoutOption [ ] _inspectorNameWidth = { GUILayout . Width ( 240 ) , GUILayout . MaxWidth ( 240 ) } ;
19- private readonly GUILayoutOption _inspectorRecordHeight = GUILayout . Height ( InspectorRecordHeight ) ;
2019
2120 private readonly List < InspectorTab > _tabs = new List < InspectorTab > ( ) ;
2221 private InspectorTab _currentTab ;
@@ -81,7 +80,7 @@ private void DrawVariableNameEnterButton(ICacheEntry field)
8180 _alignedButtonStyle = GUI . skin . button . CreateCopy ( ) ;
8281 _alignedButtonStyle . alignment = TextAnchor . MiddleLeft ;
8382 _alignedButtonStyle . wordWrap = true ;
84-
83+
8584 _alignedButtonStyleUnclickable = _alignedButtonStyle . CreateCopy ( ) ;
8685 _alignedButtonStyleUnclickable . normal . background = null ;
8786 _alignedButtonStyleUnclickable . onNormal . background = null ;
@@ -408,19 +407,54 @@ private void DrawContentScrollView(InspectorTab tab)
408407 } ) ;
409408 var visibleFields = visibleFieldsQuery . ToList ( ) ;
410409
411- var firstIndex = ( int ) ( currentItem . ScrollPosition . y / InspectorRecordHeight ) ;
410+ var scrollPositionY = ( int ) currentItem . ScrollPosition . y ;
411+ var scrollMaxVisibleY = scrollPositionY + ( ( int ) WindowRect . height - 130 ) ; // TODO conservative value, properly measure at runtime for less overdraw
412+
413+ var topCombinedHeight = 0 ;
414+ var index = 0 ;
415+
416+ // Empty space at the top
417+ for ( ; index < visibleFields . Count ; index ++ )
418+ {
419+ var newHeight = topCombinedHeight + visibleFields [ index ] . ItemHeight ;
420+ if ( newHeight >= scrollPositionY ) break ;
421+ else topCombinedHeight = newHeight ;
422+ }
412423
413- GUILayout . Space ( firstIndex * InspectorRecordHeight ) ;
424+ if ( topCombinedHeight > 0 )
425+ GUILayout . Space ( topCombinedHeight ) ;
414426
415- var currentVisibleCount = ( int ) ( WindowRect . height / InspectorRecordHeight ) - 4 ;
416- for ( var index = firstIndex ; index < Mathf . Min ( visibleFields . Count , firstIndex + currentVisibleCount ) ; index ++ )
427+ // Actual entries
428+ for ( ; index < visibleFields . Count ; index ++ )
417429 {
418430 var entry = visibleFields [ index ] ;
431+
419432 DrawSingleContentEntry ( entry ) ;
433+
434+ topCombinedHeight += entry . ItemHeight ;
435+
436+ if ( Event . current . type == EventType . Repaint )
437+ {
438+ var measured = ( int ) GUILayoutUtility . GetLastRect ( ) . height ;
439+ entry . ItemHeight = Mathf . Max ( entry . ItemHeight , measured ) ;
440+ }
441+
442+ if ( topCombinedHeight > scrollMaxVisibleY )
443+ {
444+ index ++ ;
445+ break ;
446+ }
420447 }
448+
449+ // Empty space at the bottom
450+ var bottomCombinedHeight = 0 ;
451+ for ( ; index < visibleFields . Count ; index ++ )
452+ bottomCombinedHeight += visibleFields [ index ] . ItemHeight ;
453+
421454 try
422455 {
423- GUILayout . Space ( Mathf . FloorToInt ( Mathf . Max ( WindowRect . height / 2 , ( visibleFields . Count - firstIndex - currentVisibleCount ) * InspectorRecordHeight ) ) ) ;
456+ var extraSpace = Mathf . FloorToInt ( WindowRect . height / 2 ) ;
457+ GUILayout . Space ( bottomCombinedHeight + extraSpace ) ;
424458 // Fixes layout exploding when searching
425459 GUILayout . FlexibleSpace ( ) ;
426460 }
@@ -436,7 +470,7 @@ private void DrawContentScrollView(InspectorTab tab)
436470
437471 private void DrawSingleContentEntry ( ICacheEntry entry )
438472 {
439- GUILayout . BeginHorizontal ( _inspectorRecordHeight ) ;
473+ GUILayout . BeginHorizontal ( GUILayout . Height ( entry . ItemHeight ) ) ;
440474 {
441475 try
442476 {
0 commit comments