- Home /
Auto scaling GUI
Hello everyone.
I've been looking for a solution to my problem for a while now and I didn't find anything that works.
Here is my problem:
I'm creating a web build of my project.
My website, which displays the unity web player, is auto scaling the player's size according to the user's resolution.
Is there a way to code an automatic resize of the GUI?
Thanks.
Answer by Wolfram · Jan 12, 2013 at 10:33 PM
Use GUIUtility.ScaleAroundPivot to adjust the size of your GUI to your liking. Beware of resolutions with different aspect ratio.
If you want to keep the pixel sizes of your element and just shift them around, detailed adjustment via scripting can't be avoided (although you could still use ScaleAroundPivot by keeping the scale and moving the Pivot around, for example to keep buttons aligned to the right border or something, but the exact values that are required are somewhat difficult to figure out).
Does GUIUtility.ScaleAroundPivot basically do the same as what I posted above? Could save me some time...
Just wonder how would that work in terms of quality - comparing to normal setup.
Well, all your GUI objects will no longer be pixel-perfect, since the GUI in total will be scaled up or down. But this is the only approach that doesn't require a complete reprogram$$anonymous$$g (=replacing every numeric constant with an appropriate resolution-dependent variable) of every single GUI object.
Answer by landon912 · Jan 13, 2013 at 12:14 AM
you should use a matrix(im not sure this works in web player) it will scale and position the GUI according to the aspect ratio and resolution. Ill try to find a link to them
Heres the link: http://answers.unity3d.com/questions/142829/GUI-Placement-Question.html
Note that GUIUtility.ScaleAroundPivot and GUIUtility.RotateAroundPivot are convenience methods that modifiy GUI.matrix, since it is often more complicated to mess with GUI.matrix directly, depending on what you want to accomplish.
Answer by POLYGAMe · Jan 13, 2013 at 12:22 AM
You sure can do this... for example, here's how I told my vignette (GUITexture) to be full screen size, no matter what resolution. Of course you can mess with the numbers. So you could make your buttons always be 1/8th of the screen width etc...
Vignette.guiTexture.pixelInset = Rect(-(Screen.width / 2), -(Screen.height / 2), Screen.width, Screen.height);
The first two values are the pixel inset, the third and fourth are the size of the GUITexture. So you of course want to set the pixel inset to half of the size if you want to align it to the middle. Hope I'm being clear... still a bit of a noob myself. LOL.
EDIT: I should add, the pixel inset is measured from the bottom left corner.
This explains it better than I do :P http://answers.unity3d.com/questions/43535/changing-pixel-inset-of-gui-texture-from-scripting.html
Well, you are assu$$anonymous$$g he uses the older "`GUIElement`s" GUITexture
and GUIText
, which are Components, while we are assu$$anonymous$$g he uses the newer UnityGUI (=anything that goes in OnGUI() and uses the GUI.Somefunction() methods). It's more likely he's talking about the latter, but he didn't tell us any details.
AH, I didn't even know it had changed. I'm still using GUITextures/GUITexts etc. Doh!
Well, both variants work fine. However, OnGUI() is much more powerful, since it already provides several different elements to put together (buttons, sliders, styling, ...). But the "script-the-whole-GUI-and-its-interactions-on-the-fly" does need some getting used to.
I personally, as well as our company, exclusively use regular 3D scene objects for all our GUIs for various reasons, so it's "neither/nor" for us :o)
Your answer
Follow this Question
Related Questions
GUI adapting to screen resolution? 3 Answers
Which Is The Actual Game?(Max or no Max Screen) 1 Answer
GUI and Screen Resolution 1 Answer
How to make my game fit into my droid? 1 Answer
Adjusting GUI 1 Answer