x


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.

more ▼

asked Jan 05 '12 at 09:38 AM

taar1 gravatar image

taar1
36 5 5 6

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
 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
more ▼

answered Jan 05 '12 at 12:25 PM

robert_mathew gravatar image

robert_mathew
522 27 36 44

this is the way to use in unity

Jan 05 '12 at 12:27 PM robert_mathew

That won't necessarily look good on all devices

Jan 05 '12 at 09:58 PM DaveA
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jan 05 '12 at 10:00 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

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?

Jan 06 '12 at 10:38 AM taar1
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jan 06 '12 at 02:50 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

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.

Jan 11 '12 at 01:47 AM taar1

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

Sep 06 '12 at 09:37 AM appearance
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3698
x2493
x488
x382
x8

asked: Jan 05 '12 at 09:38 AM

Seen: 6604 times

Last Updated: Sep 06 '12 at 09:37 AM