Пример #1
0
    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();
    }
Пример #2
0
    private IEnumerator ForceGameWindowAspect()
    {
        yield return(WaitFor.Seconds(3f));

        //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;
        bool requiresChange = false;

        if (width % 2 != 0)
        {
            Logger.Log($"Odd width {width}->{width - 1}", Category.Camera);
            width--;
            requiresChange = true;
        }

        int height = Screen.height;

        if (height % 2 != 0)
        {
            Logger.Log($"Odd height {height}->{height - 1}", Category.Camera);
            height--;
            requiresChange = true;
        }

        Camera main = Camera.main;

        if (!main)
        {
            yield break;
        }

        main.rect = new Rect(0, 0, width / (float)Screen.width, height / (float)Screen.height);

        if (requiresChange && !Screen.fullScreen)
        {
            Screen.SetResolution(width, height, false);
        }

        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();
    }