{"id":331,"date":"2017-11-01T21:37:43","date_gmt":"2017-11-01T10:37:43","guid":{"rendered":"https:\/\/ocias.com\/blog\/?p=331"},"modified":"2017-12-04T18:57:59","modified_gmt":"2017-12-04T07:57:59","slug":"simple-framework-beautiful-mobile-game-ui-unity","status":"publish","type":"post","link":"https:\/\/ocias.com\/blog\/simple-framework-beautiful-mobile-game-ui-unity\/","title":{"rendered":"Simple Framework for Beautiful Mobile Game UI in Unity"},"content":{"rendered":"<p>Screen design for mobile game UI can be very daunting. There is a very broad range of device resolutions, screen sizes and aspect ratios to accomodate. It&#8217;s not viable for independent artists or small teams to design a new visual layout for every screen.<!--more--><\/p>\n<p>What you need is a framework that allows you to use a single design across all devices.<\/p>\n<p>In the past, you could attach UI elements to screen borders, just specify a vertical field of view, then aim for 9:16 and automatically allow more vision on the sides on wider devices like iPads. However, with the rise of taller screens like the iPhone X, now that you face aspect ratios narrower than 9:16, meaning this approach is no longer viable. The vertical field of view will crop key elements out, and attaching UI elements to screen corners puts them far out of reach or in conflict with system gestures.<\/p>\n<p><a href=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/iPhoneXProblem.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-334 size-large\" src=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/iPhoneXProblem-1024x512.png\" alt=\"Vertical FOV doesn't work well with tall screens like iPhone X\" width=\"660\" height=\"330\" srcset=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/iPhoneXProblem-1024x512.png 1024w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/iPhoneXProblem-300x150.png 300w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/iPhoneXProblem-768x384.png 768w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/iPhoneXProblem.png 2048w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<p>The most professional solution is to make a bespoke design for every key device type. However, I work mostly independently and don\u2019t have time or money to multiply my workload that way. Instead, I&#8217;ve assembled a little design framework that elegantly accommodates a screen of any aspect ratio.<\/p>\n<h2>My Mobile Game UI Solution<\/h2>\n<p>This framework is composed of four elements:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-336\" src=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/360x640-1024x1024.png\" alt=\"a 360 by 640 pixel canvas overlaid with a 5 pixel grid\" width=\"660\" height=\"660\" srcset=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/360x640-1024x1024.png 1024w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/360x640-150x150.png 150w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/360x640-300x300.png 300w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/360x640-768x768.png 768w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/360x640.png 2048w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/p>\n<ol>\n<li>The fundamental construction of your screen is done at 360\u00d7640 resolution. While this doesn\u2019t line up to an existing Apple device point resolution, it has a number of benefits:\n<ul>\n<li>Easily divisible, including by 2, 3, 4, 5 and 8, allowing for elegant construction grids.<\/li>\n<li>Exactly one third of Full HD (1920\u00d71080) on each axis, which is the native pixel resolution of iPhone 6+\/7+\/8+ and a common Android device resolution.<\/li>\n<li>The low resolution is very human-friendly for rapidly tweaking and repositioning elements.<\/li>\n<li>Considering the pixels per centimetre of modern devices, pixel-aligned imagery is not a large concern.<\/li>\n<\/ul>\n<\/li>\n<li>A Unity canvas configuration that scales your UI to always fit on screen and behave consistently.\n<ul>\n<li>Canvas Scaler component set to &#8220;Scale with Screen Size&#8221; to resolution 360\u00d7640.<\/li>\n<li>&#8220;Screen Match Mode&#8221; set to &#8220;Expand&#8221;, meaning differences in aspect result in space being added, not removed.<\/li>\n<li>All UI elements are placed inside an empty 360\u00d7640 gameobject on the canvas. Combined with the scaler settings, this allows us to not care about the anchors or pivots of our objects. Any UI element placed within this 9\u00d716 rectangle will stay in their position &#8211; screen aspect changes will only add space on the outside.<\/li>\n<\/ul>\n<\/li>\n<li>A canvas grid gizmo script that overlays your desired grid in the viewport, so you can match your design closely.<\/li>\n<li>A camera script that takes control of your field of view, making it driven by the vertical angle when the screen is wider than 9:16, and swapping to horizontal angle when it&#8217;s narrower. This makes sure the viewport always expands out from your desired aspect ratio, meaning the visual behaviour matches the UI<\/li>\n<\/ol>\n<p>Additionally, I have included a sample project, if you would like to investigate how it works.<\/p>\n<p><a href=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-344\" src=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI-1024x1024.jpg\" alt=\"The example UI I created to go with the framework\" width=\"660\" height=\"660\" srcset=\"https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI-1024x1024.jpg 1024w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI-150x150.jpg 150w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI-300x300.jpg 300w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI-768x768.jpg 768w, https:\/\/ocias.com\/blog\/wp-content\/uploads\/2017\/11\/sampleUI.jpg 2048w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/a><\/p>\n<h2>Download<\/h2>\n<p>You can get the framework from <a href=\"https:\/\/github.com\/AlexanderOcias\/SimpleUnityMobileAspectRatioFramework\">github<\/a>, or download the <a href=\"https:\/\/ocias.com\/unitypackages\/SimpleMobileAspectRatioFramework.unitypackage\">unitypackage<\/a>.<\/p>\n<p>I hope this removes some headaches from your process, and don\u2019t hesitate to drop me a line if you end up using it, or if you run into any problems with it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Screen design for mobile game UI can be very daunting. There is a very broad range of device resolutions, screen sizes and aspect ratios to accomodate. It&#8217;s not viable for independent artists or small teams to design a new visual layout for every screen.<\/p>\n","protected":false},"author":1,"featured_media":343,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[9,3],"class_list":["post-331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-tutorial","tag-unity3d"],"_links":{"self":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts\/331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/comments?post=331"}],"version-history":[{"count":10,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts\/331\/revisions"}],"predecessor-version":[{"id":350,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/posts\/331\/revisions\/350"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/media\/343"}],"wp:attachment":[{"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ocias.com\/blog\/wp-json\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}