If I allow my window to be resized using PlayerSettings.resizableWindow, there is nothing I can see that would set a limit to how high or wide it can be.
There is no PlayerSettings.minSize, so I wrote some code to resize the window if a user attempts to adjust it, bit it does not always result in that size I enforce.
if ((Screen.height < screenSizeMinimum) || (Screen.width > Screen.height * 2)) {
Debug.LogWarning("Screen too short or too wide!");
Screen.SetResolution(screenSizeMinimum, screenSizeMinimum, false);
}
If a user tries dragging the window down beyond the screenSizeMinimum, it can end up in a state outside of the limits I am trying to enforce. In particular with this code a user can make it wide, then pull down the height, resulting in the ability to override the enforcement. Not so great.
Whether this is run on Update or FixedUpdate, makes no difference.
I think in player settings you can enforce aspect ratios, which will allow you to at least maintain your ratios. If you want to allow a resizable window, that might be the way to go. Otherwise, you may just consider having preset sizes they can choose from.
Yes, preset sizes is what I am using right now. Just wanted the feature of being able to resize the window on the fly, if a user wished. Better usability then having them type numbers into a box.
So are you asking for ideas how to fix the edge cases or do you just want to share the code?
the “but it does not always…” sounded as if you asked for some improvement. Let us know. 
This might feel like a cheap hack, but I’d recommend using a drop down menu with a list of supported resolutions rather than fully letting the window be resizable.
Reasons:
-
It’s costly performance wise. Canvases get triggered to fully recalculated every time you resized by even a single pixel.
-
I’m assuming you’re targeting Windows standalone (either that or Mac), but DirectX also involves a whole bunch of releasing resources and resizing buffers when you resize windows.
-
Some games/apps cheat around this by simply blanking out the window while resizing, and only allow redraws to happen when you stop resizing.
-
It’s a good source of bugs that may get introduced over regressions (e.g. mouse event bugs in Unity), canvas bugs, etc.
All that to say: Certainly it’s possible… but do you really want to open this can of worms?
What’s your target platform?
Looking at Windows right now, but if things go well I would expand out.
Not looking for a code fix or any tricksy way around it, just wondering if there was some simple solution that someone already knew about.