Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dorpeleg · Jan 12, 2013 at 09:05 PM · guiwebplayerresolutionscreensize

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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).

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image POLYGAMe · Jan 13, 2013 at 12:29 AM 0
Share

Does GUIUtility.ScaleAroundPivot basically do the same as what I posted above? Could save me some time...

avatar image Wolfram · Jan 13, 2013 at 12:32 AM 0
Share

It only works for OnGUI() stuff, not the GUITextures.

avatar image POLYGAMe · Jan 13, 2013 at 12:47 AM 0
Share

Ooooooh..... I see.

avatar image tomekkie2 · Jan 13, 2013 at 12:37 PM 0
Share

Just wonder how would that work in terms of quality - comparing to normal setup.

avatar image Wolfram · Jan 13, 2013 at 03:27 PM 1
Share

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.

Show more comments
avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Jan 13, 2013 at 12:21 AM 0
Share

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.

avatar image landon912 · Jan 13, 2013 at 01:08 AM 0
Share

i found it very simple, for what he is asking for. :/

avatar image
0

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image POLYGAMe · Jan 13, 2013 at 12:27 AM 0
Share

This explains it better than I do :P http://answers.unity3d.com/questions/43535/changing-pixel-inset-of-gui-texture-from-scripting.html

avatar image Wolfram · Jan 13, 2013 at 12:32 AM 0
Share

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.

avatar image POLYGAMe · Jan 13, 2013 at 12:48 AM 0
Share

AH, I didn't even know it had changed. I'm still using GUITextures/GUITexts etc. Doh!

avatar image Wolfram · Jan 13, 2013 at 12:59 AM 0
Share

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)

avatar image POLYGAMe · Jan 13, 2013 at 01:02 AM 0
Share

Hehe, I'll stick with what I know. lol.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges