I’ve noticed inside the Editor and when running a standalone that the GUI will not scale itself and that placing GUI elements such as Labels are not relative to the screen but absolute desktop resolution offsets!
So the end result here is that unless my application is used at precisely the resolution I built it inside the Editor, it will be all wrong.
If you want scaling buttons and labels, try using GUILayout with the ExpandWidth and/or ExpandHeight options.
If you want GUI where the element positions adapt to the resolution, you have two main options:
You can group GUI elements between the GUI.BeginGroup() and GUI.EndGroup() calls. Then you can move the group to adapt to different resolutions.
Or, with the GUILayout, you have the GUILayout.FlexibleSpace(). Using this inserts space between your elements which will stretch or contract as the resolution changes.
thanks for the reply, though maybe I wasn’t entirely clear the problem is with the font rendering… it will always stay at the same size rather than scale relative to the application resolution
Attached are two shots of the same GUI one at 1600x900 and the other at 640x480.
So two end-users running your application at different resolutions will have entirely different GUI’s - and you can see how this could quickly become a pile of garbage on the screen at certain resolutions.
In other applications/engines I’ve used often a ‘virtual’ GUI canvas is defined, so numbers and scales and sizes are all relative to the virtual canvas… which allows for scaling no problems.
But if this is how the Unity GUI’s are, fair enough, then what are developers doing about it in their applications?
Or you could use this line when you start your code
function OnGUI () {
GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity,Vector3(Screen.width / 1024.0, Screen.height / 768.0, 1));//All one line
///@@@///==YOUR CODE HERE==///@@@///
}
Just set the desired screen res in the screen h w.
i think there is even a couple of other waus to auto scale with screen res. And there are a couple of scripts on the wiki for scaling a GUITexture if you need it.
That’s how I do it too, but better not to put that in your OnGUI method as it gets called several times per frame. Better to calculate it once when the screen resolution is changed/detected and cache it for use in the OnGUI function.
The solution of using a GUI.matrix to adapt the GUI to any resolution seems to work perfect but when I use a panoramic 16:9 resolution all my GUI is expanded too much. Is there a solution for this? Maybe using another matrix when the aspect is 16:9?