Targeting Multiple Aspect Ratios using Unity3D

Unity3D GUI is hell. Add multiple aspect ratios and you’d pretty much be pulling your hair off.

For those developers who are new to tackling multiple aspect ratios; here’s a project that you could test out.

MultiAspectRatioTest
MultiAspectRatioTest
MultiAspectRatioTest.zip
182.0 KiB
199 Downloads
Details

The main issue with different aspect ratios (and screen resolutions) is that they “see” things differently. You could solve this by either using Pillarbox/Letterboxing or Stretching. Pillarbox/Letterboxing is totally out of the question. Nobody likes losing screen real estate. Googling around and you’ll see suggestions of stretching the GUI by manipulating the GUI.matrix via Matrix4x4.SetTRS() but stretching is not cool.

For 3D games, this is barely an issue. For 2D games, yes it is. It’s also an annoyance to the develop User Interfaces for different aspect ratios. Then I stumbled upon How to support 3 iOS aspect ratios in Unity3D which showed how to use a single camera to be deployed in multiple devices with different aspect ratios. The solution: change the orthographic size of the camera! However, there were some discrepancies with the exact pixel values which led me to create the test project above. Nigel also mentioned to use the orthographic size for the UI.

As for the User Interface, to hell with Unity3D GUI since you can’t even see it while you’re coding. Sprites are way better. It makes the world a better place for game developers. Combined with a dedicated camera to draw the user interface from sprites and Text Mesh for dynamic text, we can actually replace most of the form elements in GUI. 

I ran my project on an iPhone 5s, iPhone 3GS and iPad 3 and the results are as follows.

iPhone 5siPhone 5s

iPad3

iPad 3

iPhone 3gs

iPhone 3GS (with a different font size)

What does this mean? Keep your game elements inside the green box and it will be seen in any of the 3 aspect ratios. Then for your UI, use sprites and see how I aligned those orange boxes to the top/bottom edges of the screen. What about the extra space on wider aspect ratios, up to you actually.