private IEnumerator ForceGameWindowAspect() { yield return(WaitFor.Seconds(1.2f)); //The following conditions check if the screen width or height //is an odd number. If it is, then it adjusted to be an even number //This fixes the sprite bleeding between tiles: int width = Screen.width; if (width % 2 != 0) { Logger.Log($"Odd width {width}->{width-1}", Category.Camera); width--; } int height = Screen.height; if (height % 2 != 0) { Logger.Log($"Odd height {height}->{height-1}", Category.Camera); height--; } Camera main = Camera.main; if (!main) { yield break; } Logger.Log("Screen height before resizing: " + main.pixelHeight + " Aspect Y: " + height / (float)Screen.height, Category.Camera); Logger.Log("Screen width before resizing: " + main.pixelWidth + " Aspect X: " + width / (float)Screen.width, Category.Camera); // Enforce aspect by resizing the camera rectangle to nearest (lower) even number. main.rect = new Rect(0, 0, width / (float)Screen.width, height / (float)Screen.height); Logger.Log("Screen height after resizing: " + main.pixelHeight, Category.Camera); if (camResizer != null) { camResizer.AdjustCam(); } screenWidthCache = Screen.width; screenHeightCache = Screen.height; //Refresh UI (helps avoid event system problems) parentCanvas.enabled = false; canvasScaler.enabled = false; graphicRaycaster.enabled = false; yield return(WaitFor.EndOfFrame); parentCanvas.enabled = true; canvasScaler.enabled = true; graphicRaycaster.enabled = true; monitorWindow = true; checkingDisplayOnLoad = false; cameraZoomHandler.Refresh(); }
private IEnumerator ForceGameWindowAspect() { yield return(new WaitForSeconds(0.2f)); if (!Screen.fullScreen) { float screenWidth = Screen.height * targetAspect; //The following conditions check if the screen width or height //is an odd number. If it is, then it adjusted to be an even number //This fixes the sprite bleeding between tiles: if ((int)screenWidth % 2 != 0) { screenWidth += 1f; } int screenHeight = Screen.height; if (screenHeight % 2 != 0) { screenHeight++; } Screen.SetResolution((int)screenWidth, screenHeight, false); if (camResizer != null) { camResizer.AdjustCam(); } Camera.main.ResetAspect(); screenWidthCache = Screen.width; screenHeightCache = Screen.height; } //Refresh UI (helps avoid event system problems) parentCanvas.enabled = false; canvasScaler.enabled = false; graphicRaycaster.enabled = false; yield return(new WaitForEndOfFrame()); parentCanvas.enabled = true; canvasScaler.enabled = true; graphicRaycaster.enabled = true; monitorWindow = true; checkingDisplayOnLoad = false; }
IEnumerator ForceGameWindowAspect() { yield return(new WaitForSeconds(0.2f)); if (!Screen.fullScreen) { float screenWidth = (float)Screen.height * targetAspect; Screen.SetResolution((int)screenWidth, Screen.height, false); camResizer.AdjustCam(); Camera.main.ResetAspect(); screenWidthCache = Screen.width; screenHeightCache = Screen.height; } //Refresh UI (helps avoid event system problems) parentCanvas.enabled = false; canvasScaler.enabled = false; graphicRaycaster.enabled = false; yield return(new WaitForEndOfFrame()); parentCanvas.enabled = true; canvasScaler.enabled = true; graphicRaycaster.enabled = true; monitorWindow = true; }