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
1
Question by taar1 · Jan 05, 2012 at 09:38 AM · androidguiresolutionscreendensity

Fit GUI to various android screen resolutions and densities

Is there a way to automatically get a game made with Unity to fit to the numerous Android screen resolutions and densities? As for iOS we could just use a list with the various resolutions but as for Android there are just so many devices. It's impossible to create a list like that.

Thanks for any help in advance.

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

6 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robert_mathew · Jan 05, 2012 at 12:25 PM

  GUI.Button(new Rect(Screen.width * (1f/6.55f),Screen.height * (0.1f/6.3f),Screen.width * (4.8f/6.55f), Screen.height * (0.85f/6.3f)),"Click"); //c#

  GUI.Button(Rect(Screen.width * (1f/6.55f),Screen.height * (0.1f/6.3f),Screen.width * (4.8f/6.55f), Screen.height * (0.85f/6.3f)),"Click"); //java script
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 robert_mathew · Jan 05, 2012 at 12:27 PM 0
Share

this is the way to use in unity

avatar image DaveA · Jan 05, 2012 at 09:58 PM 0
Share

That won't necessarily look good on all devices

avatar image
1

Answer by DaveA · Jan 05, 2012 at 10:00 PM

Until 3.5b, you couldn't get the physical size of the screen for choosing good layout options. Now you can. I think it best to have at least 2 layouts you can choose from, based on resolution and screen size (DPI). Meaning, a small device with a low res screen will look better if you gear it toward that, but a small device with a high-res screen will look unuasable where that same layout would be just fine on a tablet screen. So you should have some to choose from.

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 taar1 · Jan 06, 2012 at 10:38 AM 0
Share

What's the equivalent version number of Unity for Windows to 3.5b? I'm using 3.4.2f3 with Windows. I'm quite new to Unity so I'm not too well acquainted with it yet.

So I made a CameraCheck.js file and attached it to the game scene. The script's doing something like that so far:

public var camera : Camera;

function Start() {

if ( Application.platform == RuntimePlatform.Android ) {

    var resolution : Resolution = Screen.currentResolution;
    
   if ( resolution.width == X && resolution == Y ) {
         //Do something to the camera
   }

}

}

I'm wondering now how to detect/get the proper screen resolution and how I control the camera with those values?

avatar image
1

Answer by Statement · Jan 06, 2012 at 02:50 PM

For earlier Unity versions;

You can scale the gui with GUI.matrix. If you design the GUI for the lowest supported resolution, you can then scale up the GUI for the other resolutions, given they are of the same aspect ratio to not get a squashed look. If you plan on supporting different aspect ratios, then make designs for the lowest resolution aspect ratios. Obviously, it won't produce high end graphics for those with bigger resolution since it'll just scale up the graphics, but the elements will occupy the same amount of screen space.

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 taar1 · Jan 11, 2012 at 01:47 AM 0
Share

Thanks for the info. So with GUI.matrix I can scale the GUI but how do I get the resolution of the physical Android device? For instance the Nexus One has 480x800 pixels while the Galaxy Nexus has 720x1280. I don't know how I can get that information in the first place.

avatar image appearance · Sep 06, 2012 at 09:37 AM 0
Share

You can use Screen.currentResolution.width & Screen.currentResolution.height to know about the current resolution of your device.

avatar image
0
Wiki

Answer by peterwilli · Mar 14, 2014 at 09:57 AM

Hi guys,

I use this kind of trick to create a cross-platform solution.

 using UnityEngine;
 using System.Collections;
 
 public class Singleton : MonoBehaviour {
 
     private static Singleton instance = null;
     public static float denistyScale;
     
     public static Singleton Instance {
         get { return instance; }
     }
     
     void Awake() {
         if (instance != null && instance != this) {
             Destroy(this.gameObject);
             return;
         } else {
             instance = this;
         }
         Singleton.denistyScale = Screen.dpi / 160;
         DontDestroyOnLoad(this.gameObject);
     }
 }

Just multiply everything you want "as-is" on multiple densities by Singleton.densityScale. Example usage:

 score.fontSize = 20 * Singleton.denistyScale;

Tested on:

  • iPad (Retina display)

  • Some androids

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 AronTD · May 30, 2014 at 12:54 PM 0
Share

Why divide by 160?

avatar image
0

Answer by selvap · Mar 14, 2014 at 11:09 AM

the best way to fit the gui texture on every screen is :

Try the follwing this...its works for every screen aspect ratio even for both ios android.

Steps:

1.Create a GUITexture. 2.In GUITexture parameter keep pixel inset to 0.(for everything). 3.Adjust the position and scale value in in Transform inspector. 4.then use this script

using UnityEngine; using System.Collections;

public class GUI_Controller : MonoBehaviour { public Vector2 scaleOnRatio1 = new Vector2(0.1f, 0.1f); private Transform myTrans; private float widthHeightRatio;

 void Start () 
 {
     myTrans = transform;
     SetScale();
 }

 void SetScale()
 {
     //aspect ratio
     widthHeightRatio = (float)Screen.width/Screen.height;
     
     //Apply the scale. We only calculate y since our aspect ratio is x (width) authoritative: width/height (x/y)
     myTrans.localScale = new Vector3 (scaleOnRatio1.x, widthHeightRatio * scaleOnRatio1.y, 1);
 }



 }



5.Adjust the scale ratio in script transform... 6.TA ta i....i will works like boss..

thank u..

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 AronTD · May 30, 2014 at 12:56 PM 0
Share

Where does scaleOnRatio1 come from. Needs more explanation.

  • 1
  • 2
  • ›

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

Android Button Screen 1 Answer

Finding Screen Resolution of an Android Device 0 Answers

How to make my game fit into my droid? 1 Answer

Excluding android devices with resolution less than X 0 Answers

GUI and Screen Resolution 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