-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Mastering UI Development with Unity
By :

A game’s resolution is the pixel dimension of the screen on which it plays. For example, a game could run at 1,024x768. This means that the game is 1,024 pixels wide and 768 pixels tall. The aspect ratio of a game is the ratio of the width and height (expressed as width:height). This aspect ratio is determined by dividing the resolution width by the resolution height and then simplifying the fraction. So, for example, if your game has a resolution of 1024x768, the aspect ratio would be as follows:
1024px/768px=4/3
Here, the fraction 4/3 is the aspect ratio 4:3.
The following table provides a list of common aspect ratios and related resolutions:
Figure 1.3: Common aspect ratios and resolutions
When designing your UI, the resolution and aspect ratio will play an important role in how your UI will look. Knowing the resolution and aspect ratio of your target device will be an important first step in designing your UI for two reasons:
If you build to a single resolution/aspect ratio, the UI will be much easier to build as you won’t have to make sure all the elements maintain their relative position at multiple aspect ratios. However, if you build a game that will run at multiple resolutions/aspect ratios (for example, a mobile project or a web game that scales within a window), you want your UI to scale and move appropriately. You’ll also want to be able to easily change the resolution during testing so that you can make sure the UI is positioned appropriately as its display window morphs.
Even if you will allow your resolution and aspect ratio to vary, you should still decide on a default resolution. This default resolution represents the resolution of your ideal design. This will be the resolution that your initial design and UI layout are based on, so if the resolution or aspect ratio varies, the UI will try to maintain the same design as best it can.
Note
Since all televisions sold today have a 16:9 aspect ratio, any UI you make for a console game should be developed with a 16:9 aspect ratio in mind.
You can easily switch between different resolutions and aspect ratios in the Game tab. This will allow you to see how your UI scales at the different resolutions and aspect ratios:
Figure 1.4: Selecting Free Aspect mode from the Game view
The items displayed in this list are the most common aspect ratios and resolutions for the build target you currently have selected. In the preceding screenshot, my build target was PC, Mac & Linux Standalone, so the most common monitor settings are displayed. If I were to change my build target to iOS, I would see a list of popular iPhone and iPad screen dimensions.
Free Aspect means that the game’s aspect ratio will scale relative to the window of the Game view. So, by moving the frame around on the Game window, you will change the aspect ratio.
Figure 1.5: Changing the Editor Layout
Now the Game and Scene tabs will both be visible on the left-hand side of your screen.
Figure 1.6: Results of the 2 by 3 layout
Figure 1.7: Results of resizing the Game view in Free Aspect mode
Figure 1.8: Game view scale
Figure 1.9: Adding a new resolution or aspect ratio preset
For example, if you wanted to make a game that was reminiscent of an old Game Boy game, you could add a 160x144 pixels preset:
Figure 1.10: Creating a fixed resolution preset
Figure 1.11: Selecting a custom preset
If you are creating a game that you plan to build on the PC, Mac, & Linux Standalone target platform, you can force the resolution to always be the same. To do so, go to Edit | Project Settings | Player. Your Inspector should now display the following:
Figure 1.12: PC, Mac & Linux Standalone Player resolution settings
You may have more or fewer platforms displayed here; it depends on the modules you have installed with Unity.
To force a specific resolution on a PC, Mac, & Linux Standalone game, deselect Default is Native Resolution. The option to input Default Screen Width and Default Screen Height will be made available to you and you can enter the desired resolution values. Then, when you build your game, it will play at the size you specified.
The following screenshot shows the settings for forcing a PC game to play in a window with Game Boy Color dimensions:
Figure 1.13: Setting a specific PC, Mac, & Linux Standalone Player resolution
You can also force a specific resolution with a WebGL build. There are fewer options to worry about, but the general concept is the same. The following screenshot shows the settings for forcing your game to display at 160x140 in the Player Settings for WebGL:
Figure 1.14: Setting a specific WebGL resolution
In Chapter 2, we will discuss how to set the resolution properties for mobile games that have varying resolutions that you cannot pre-define.