Resolution messed up after switching between fullscreen modes.

Hello,

We’ve been struggling with this issue for quite some time. We’ve looked around the net and asked others but to no avail. So in the hope somebody here has an answer, here goes:

Our game window can be resized to the player’s liking. The game itself will adjust the viewport accordingly and keep a good aspect, adding letter- /pillarboxes if necessary. This all works fine. When the game window is left in it’s native resolution state and fullscreen mode is toggled on, you’d get the expected result: fullscreen in the best supported resolution. However when you resize the game window manually and enter fullscreen after doing so the gameview becomes all stretched and weird. Same goes for when you exit fullscreen mode again.

Below are snippets of the code:

LetterBoxing.cs attached to the MainCamera objects.

void LateUpdate()
    {
        targetaspect = 16.0f / 9.0f;
        windowaspect = (float)Screen.width / (float)Screen.height;
        scaleheight = windowaspect / targetaspect;
        Camera camera = GetComponent<Camera>();

        // Letterbox
        if (scaleheight < 1.0f)
        {
            Rect rect = camera.rect;

            rect.width = 1.0f;
            rect.height = scaleheight;
            rect.x = 0;
            rect.y = (1.0f - scaleheight) / 2.0f;

            camera.rect = rect;
        }
        else // Pillarbox
        {
            float scalewidth = 1.0f / scaleheight;

            Rect rect = camera.rect;

            rect.width = scalewidth;
            rect.height = 1.0f;
            rect.x = (1.0f - scalewidth) / 2.0f;
            rect.y = 0;

            camera.rect = rect;
        }
    }

UIManagerScript.cs used throughout the mainmenu’s settings.

    public void OnOffFullscreen()
    {
        if (UI_Toggle_Fullscreen.GetComponent<Toggle>().isOn)
        {
            Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, true);
        }
        else
        {
            Screen.fullScreen = false;
        }
    }

Any and all help would be appreciated.
Kind regards.

It appeared to be a problem within Unity afterall.
As of Patch 5.2.1p2 (october 1) this has been fixed it seems.