fix(game-loop): 修复分辨率切换后视口未正确更新问题
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user