Sometime last week I took on the task of figuring out how to get the Unity3D Windows Standalone Player to play The Wild Eternal in a fullscreen borderless window. The only solution I could find was one that required adding a command line argument to the executable. Not exactly user-friendly…
Below is my solution to this problem, which began as a simple fullscreen borderless window toggle but became a general purpose resolution controller. The system remains fairly simple, but it can toggle display modes, resolutions and control the position of the window carefully (even when borderless). It will also guess at the best display settings for a user, and save most of their settings (though you will likely wish to integrate into your own save system).
How It Works
I found that I needed to use the windows API (user32.dll) to do this, and unfortunately ran into a few problems. I resolved them, but the resolution required deviating from some statements in the windows API’s documentation (scary!)! Thanks to a handful of volunteers, I have tested this algorithm on ~30 unique Windows machines spanning 32-bit and 64-bit Windows 7, and Windows 8. Of the 30-some tests, 100% had identical results. Comforting. The details of what is scary is outlined very carefully in the code in the WindowsHandler.TrySetDisplay method.
This is repeated at the header of the ResolutionController.cs script in the shared code, so don’t feel a need to commit it to memory immediately.
For exclusive fullscreen mode, DirectX 9 games must put their Project’s D3D9 Fullscreen Mode in ExclusiveMode, not FullscreenWindow. DirectX 11 games cannot access exclusive fullscreen mode at all due to how it is implemented in Unity. This is likely not a problem as exclusive mode is only necessary for small GPU-related performance considerations, which most DirectX 11 games probably view as negligible. For those who don’t know, as I didn’t, exclusive mode is a mode where the rest of the windows explorer is not rendered (on that display), which can reduce GPU and CPU loads.
I am more than happy to answer any questions in the comments section below. Please let me know of any unexpected behavior or bugs.