perfect resolution camera/window

I’m trying to make it so that trying to scale up the game will just take the game (at 160 x 144 Pixels) and just jump to the next perfect resolution( 320 x 288, 480 x 432, 640 x 576, ect…) instead of just stretching out the game,
but if possible i would like to fill the edges with a background texture until the window stretches out to a possible resolution then make the jump to it so that full screen is still possible.

I’m happy to clarify if its needed.

Choose an aspect ratio, then you can do something like this:

void Start()  {
        cam = GetComponent<Camera>();
        var targetaspect = 4.0f / 3.0f;
        var windowaspect = (float) Screen.width / (float) Screen.height;
        var scaleheight = windowaspect / targetaspect;
        var rect = cam.rect;
        if (scaleheight < 1.0f) {
            rect.width = 1.0f;
            rect.height = scaleheight;
            rect.x = 0;
            rect.y = (1.0f - scaleheight) / 2.0f;
        } else {
            var scalewidth = 1.0f / scaleheight;
            rect.width = scalewidth;
            rect.height = 1.0f;
            rect.x = (1.0f - scalewidth) / 2.0f;
            rect.y = 0;
        }
        cam.rect = rect;
    }
1 Like