From 5ce289a6879142bdbbf4388ff53fc7e8532d3670 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Wed, 15 Apr 2026 22:23:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(game-loop):=20=E4=BF=AE=E5=A4=8D=E5=88=86?= =?UTF-8?q?=E8=BE=A8=E7=8E=87=E5=88=87=E6=8D=A2=E5=90=8E=E8=A7=86=E5=8F=A3?= =?UTF-8?q?=E6=9C=AA=E6=AD=A3=E7=A1=AE=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Game Loop/GameManager.cs | 34 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Game Loop/GameManager.cs b/Assets/Scripts/Game Loop/GameManager.cs index fdf6451ec..98dfcc640 100644 --- a/Assets/Scripts/Game Loop/GameManager.cs +++ b/Assets/Scripts/Game Loop/GameManager.cs @@ -195,23 +195,43 @@ namespace AibisDream public void SetScreenMode(string windowMode) { + int targetWidth, targetHeight; switch (windowMode) { case "FullScreen": - Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, - FullScreenMode.FullScreenWindow); + targetWidth = Screen.currentResolution.width; + targetHeight = Screen.currentResolution.height; + Screen.SetResolution(targetWidth, targetHeight, FullScreenMode.FullScreenWindow); break; case "Windowed": - Screen.SetResolution(1920, 1080, FullScreenMode.Windowed); + targetWidth = 1920; + targetHeight = 1080; + Screen.SetResolution(targetWidth, targetHeight, FullScreenMode.Windowed); break; case "MaximizedWindow": - Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, - FullScreenMode.MaximizedWindow); + targetWidth = Screen.currentResolution.width; + targetHeight = Screen.currentResolution.height; + Screen.SetResolution(targetWidth, targetHeight, FullScreenMode.MaximizedWindow); break; + default: + return; } - ActionKit.DelayFrame(1, () => CameraKit.Instance.UpdateCameraViewport(windowMode == "Windowed")) - .StartGlobal(); + StartCoroutine(WaitForResolutionAndUpdateViewport( + targetWidth, targetHeight, windowMode == "Windowed")); + } + + private IEnumerator WaitForResolutionAndUpdateViewport( + int targetWidth, int targetHeight, bool reset) + { + float timeout = Time.unscaledTime + 1f; + while ((Screen.width != targetWidth || Screen.height != targetHeight) + && Time.unscaledTime < timeout) + { + yield return null; + } + + CameraKit.Instance.UpdateCameraViewport(reset); } #endregion