|
18 | 18 | using UnityEngine.SceneManagement; |
19 | 19 | using UnityEngine.UI; |
20 | 20 | using System.Runtime.CompilerServices; |
| 21 | +using System.Collections; |
21 | 22 | #if INPUT_SYSTEM_INSTALLED |
22 | 23 | using UnityEngine.InputSystem; |
23 | 24 | using UnityEngine.InputSystem.UI; |
@@ -86,6 +87,7 @@ internal sealed class DevConsoleMono : MonoBehaviour |
86 | 87 | [Header("Logs")] |
87 | 88 | [SerializeField] private GameObject _logFieldPrefab = null; |
88 | 89 | [SerializeField] private RectTransform _logContentTransform = null; |
| 90 | + [SerializeField] private ScrollRect _logScrollView = null; |
89 | 91 |
|
90 | 92 | [Header("Window")] |
91 | 93 | [SerializeField] private RectTransform _dynamicTransform = null; |
@@ -282,9 +284,9 @@ internal void ClearConsole() |
282 | 284 |
|
283 | 285 | internal void SubmitInput() |
284 | 286 | { |
285 | | - if (!string.IsNullOrWhiteSpace(InputText)) |
| 287 | + if (!string.IsNullOrWhiteSpace(InputText) && RunCommand(InputText)) |
286 | 288 | { |
287 | | - RunCommand(InputText); |
| 289 | + ScrollToBottom(); |
288 | 290 | } |
289 | 291 |
|
290 | 292 | InputText = string.Empty; |
@@ -1709,13 +1711,24 @@ private void RefreshLogFieldsSize() |
1709 | 1711 | RebuildLayout(); |
1710 | 1712 | } |
1711 | 1713 |
|
1712 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
1713 | 1714 | private void RebuildLayout() |
1714 | 1715 | { |
1715 | 1716 | // Forcefully rebuild the layout, otherwise transforms are positioned incorrectly |
1716 | 1717 | LayoutRebuilder.ForceRebuildLayoutImmediate(_logContentTransform); |
1717 | 1718 | } |
1718 | 1719 |
|
| 1720 | + private void ScrollToBottom() |
| 1721 | + { |
| 1722 | + IEnumerator ScrollToBottomCoroutine() |
| 1723 | + { |
| 1724 | + yield return new WaitForEndOfFrame(); |
| 1725 | + _logScrollView.verticalNormalizedPosition = 0f; |
| 1726 | + } |
| 1727 | + |
| 1728 | + // Start the coroutine that snaps the scroll view at the end of the frame |
| 1729 | + StartCoroutine(ScrollToBottomCoroutine()); |
| 1730 | + } |
| 1731 | + |
1719 | 1732 | #endregion |
1720 | 1733 |
|
1721 | 1734 | #region Physical input methods |
|
0 commit comments