Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by BobbyDoogle · Oct 02, 2015 at 03:28 PM · guiresolutionaspect-ratio

GUI Matrix vs Canvas vs Alternate 2D GUI Multi Resolution Support

I'm embarking on a 2d project that will need to run on a number of aspect ratios, mainly popular phones/tablets and PC/Mac. The project is an RPG, so there will be a number of menus, dialog, battle, shops, etc. Recently I completed a project with applying GUI scale to simply scale the GUI to the screen size. Basically code like this:

 public class example: MonoBehaviour{
     float originalWidth = 1920;
     float originalHeight = 1080;
     Vector3 scale;
     public GUISkin guiSkin;
 
     void OnGUI(){
         GUI.depth = 1;
         GUI.skin = guiSkin;
         scale.x =  (float)Screen.width/originalWidth; 
         scale.y = (float)Screen.height/originalHeight;
         scale.z = 1;
         Matrix4x4 svMat = GUI.matrix;
         GUI.matrix = Matrix4x4.TRS(new Vector3(0,0,0), Quaternion.identity, scale);
 
         //all my GUI code goes here
 
         GUI.matrix = svMat;
     }
 }

This works Good. However, I am aware it will distort GUI to some extent on different aspect ratios. I have looked into Canvas and anchoring a few times, however I dislike creating my GUI in word space, and prefer to code everything, of which this approach doesn't seem particular conducive.

So, my question: Is there a good best practice for making clean 2d GUIs that support multiple resolutions, perhaps a tutorial, and or some code snips would be helpful. This is a general question, but I appreciate any pointers.

Comment
Add comment · Show 1
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 BobbyDoogle · Oct 02, 2015 at 03:38 PM 0
Share

I'm also considering having a list of button locations (x, y, length, width), generally including individual ones for every interface. Then I can call out different placements based on different aspect ratios, of which I would detect on launch or resolution change. I would still use the matrix to scale it to the actual screen size.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Trlgger · Oct 02, 2015 at 09:52 PM

If your not completely attached to GUI scripting you can use uGUI, the new Unity4.6-5 GUI system also called Canvas. It will scale with the screen resolution depending on the settings you choose and it's very easy to get the hang of.

Here is a quick tutorial supplied by Unity to get you started: https://www.youtube.com/watch?v=OD-p1eMsyrU

Comment
Add comment · Show 1 · 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 BobbyDoogle · Oct 03, 2015 at 02:04 AM 0
Share

Interesting, I was preferring scripting it, but this looks like a generally good approach, I'll look into it.

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

36 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Set Game Resolution For Every Screen 0 Answers

How to create scene with multiple panels? 0 Answers

How do I change the orientation of my game to portrait? 0 Answers

Standalone game's built version is zoomed in at most resolutions. Looks fine in game view. 1 Answer

Resolution messed up after switching between fullscreen modes. 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