Hello,
We have a service that runs a VNC session through a browser. In this session we are running a Unity standalone application. When the browser is resized, the desktop resolution is changed to match the new size of the browser window. The Unity window is maximized so it automatically resizes as well. However, Unity reports the screen size (Screen.currentResolution.width/height) and window size (Screen.width/height) incorrectly after resizing. I have confirmed that windows is correctly detecting the change in screen size and is sending the correct messages to the window.
To get information for the issue I was getting reports on the size of the screen and the window from the following places:
- Unity - Screen.currentResolution.width, Screen.currentResolution.height
- Unity - Screen.width, Screen.height
- Windows – GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)
- Windows – GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)
- Windows – GetWindowRect
Windows correctly reports the size of the window and screen, and sends the WM_DISPLAYCHANGE message to the window. However, despite resizing with the screen, Unity reports that the screen size has remained the same. There are a few issues when the resolution is increased from the starting resolution. Unity seems to be enforcing a maximum size and caps Screen.SetResolution at what it believes to be the size of the screen. Despite this, the window can still be made larger than this limit by maximizing it. However, exceeding this size causes a couple of issues described below.
- The UI gets stretched to fit the actual window dimension and becomes distorted & blurry
- Interacting in the UI with the mouse does not work as expected. You need to click at the pixel offset of the button based on the size of the screen according to Unity. However, since the screen is not actually this size to click a button you need to click above and to the left of where the button is on screen.
If you can answer any of these questions it would be a great help with fixing the issue.
- What is Unity using to determine when the resolution changes?
- Is there a way we can force Unity to update the screen resolution.
- Is there a way to force Unity to use a screen size larger than what it believes the screen resolution to be?
- Screen.SetResolution is capped at the original resolution.
- Resizing the window in Windows causes the above symptoms.
Thank you for your help,
Aaron