Skip to content

Commit 39d3896

Browse files
committed
Window resets when window size changes.
1 parent 6356d34 commit 39d3896

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Runtime/DevConsoleMono.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
123123
private Color _resizeButtonColour = default;
124124
private float _initLogFieldWidth = 0f;
125125
private float _currentLogFieldWidth = 0f;
126+
private Vector2Int _screenSize = default;
126127

127128
#endregion
128129

@@ -192,6 +193,7 @@ internal void EnableConsole()
192193
//Application.logMessageReceivedThreaded += OnLogMessageReceived;
193194
ClearConsole();
194195
InputText = string.Empty;
196+
_screenSize = new Vector2Int(Screen.width, Screen.height);
195197
ConsoleIsEnabled = true;
196198
enabled = true;
197199
}
@@ -282,6 +284,15 @@ internal void ClearConsole()
282284
_logTextStore = ClearLogText;
283285
}
284286

287+
internal void ResetConsole()
288+
{
289+
// Reset the position and size of the console
290+
_dynamicTransform.anchoredPosition = _initPosition;
291+
_dynamicTransform.sizeDelta = _initSize;
292+
_currentLogFieldWidth = _initLogFieldWidth;
293+
RefreshLogFieldsSize();
294+
}
295+
285296
internal void SubmitInput()
286297
{
287298
if (!string.IsNullOrWhiteSpace(InputText) && RunCommand(InputText))
@@ -599,6 +610,13 @@ private void Update()
599610
return;
600611
}
601612

613+
// Check if the resolution has changed and the window should be rebuilt / reset
614+
if (_screenSize.x != Screen.width || _screenSize.y != Screen.height)
615+
{
616+
_screenSize = new Vector2Int(Screen.width, Screen.height);
617+
ResetConsole();
618+
}
619+
602620
// Force the input field to be focused by the event system
603621
if (_focusInputField)
604622
{
@@ -757,13 +775,7 @@ private void InitBuiltInCommands()
757775
"reset",
758776
"",
759777
"Reset the position and size of the developer console",
760-
() =>
761-
{
762-
_dynamicTransform.anchoredPosition = _initPosition;
763-
_dynamicTransform.sizeDelta = _initSize;
764-
_currentLogFieldWidth = _initLogFieldWidth;
765-
RefreshLogFieldsSize();
766-
}
778+
() => ResetConsole()
767779
));
768780

769781
AddCommand(Command.Create(

0 commit comments

Comments
 (0)