@@ -155,6 +155,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
155155 private readonly TextGenerator _textGenerator = new TextGenerator ( ) ;
156156 private int _vertexCount = 0 ;
157157 private int _initLogTextSize = 0 ;
158+ private bool _pretendScrollAtBottom = false ;
158159
159160 #endregion
160161
@@ -382,6 +383,7 @@ internal void ClearConsole()
382383 ClearLogFields ( ) ;
383384 _vertexCount = 0 ;
384385 StoredLogText = ClearLogText ;
386+ _pretendScrollAtBottom = true ;
385387 }
386388
387389 internal void ResetConsole ( )
@@ -397,7 +399,7 @@ internal void SubmitInput()
397399 {
398400 if ( ! string . IsNullOrWhiteSpace ( InputText ) && RunCommand ( InputText ) )
399401 {
400- ScrollToBottomAtEndOfFrame ( ) ;
402+ ScrollTo ( 0.0f ) ;
401403 }
402404
403405 InputText = string . Empty ;
@@ -887,9 +889,12 @@ private void LateUpdate()
887889 // Process the stored logs, displaying them to the console
888890 if ( StoredLogText != string . Empty )
889891 {
892+ bool scrollToBottom = _logScrollView . verticalNormalizedPosition < 0f || Mathf . Approximately ( _logScrollView . verticalNormalizedPosition , 0f ) ;
893+ float scrollTo = scrollToBottom || _pretendScrollAtBottom ? 0.0f : _logScrollView . verticalNormalizedPosition ;
890894 string logText = string . Copy ( StoredLogText ) ;
891895 StoredLogText = string . Empty ;
892896 ProcessLogText ( logText ) ;
897+ ScrollTo ( scrollTo ) ;
893898 }
894899
895900 // Check if the developer console toggle key was pressed
@@ -2635,17 +2640,21 @@ private void RebuildLayout()
26352640 LayoutRebuilder . ForceRebuildLayoutImmediate ( _logContentTransform ) ;
26362641 }
26372642
2638- private void ScrollToBottomAtEndOfFrame ( )
2643+ private void ScrollTo ( float vertical )
26392644 {
2640- IEnumerator ScrollToBottomCoroutine ( )
2645+ IEnumerator ScrollTo ( )
26412646 {
26422647 yield return new WaitForEndOfFrame ( ) ;
2643- _logScrollView . verticalNormalizedPosition = 0f ;
2644- _logScrollView . CalculateLayoutInputVertical ( ) ;
2648+ _logScrollView . verticalNormalizedPosition = vertical ;
2649+ LayoutRebuilder . ForceRebuildLayoutImmediate ( ( RectTransform ) _logScrollView . transform ) ;
2650+ if ( _pretendScrollAtBottom && ( _logScrollView . verticalNormalizedPosition < 0f || Mathf . Approximately ( _logScrollView . verticalNormalizedPosition , 0f ) ) )
2651+ {
2652+ _pretendScrollAtBottom = false ;
2653+ }
26452654 }
26462655
26472656 // Start the coroutine that snaps the scroll view at the end of the frame
2648- StartCoroutine ( ScrollToBottomCoroutine ( ) ) ;
2657+ StartCoroutine ( ScrollTo ( ) ) ;
26492658 }
26502659
26512660 #endregion
0 commit comments