Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering UI Development with Unity
Mastering UI Development with Unity

Mastering UI Development with Unity: An in-depth guide to developing engaging user interfaces with Unity 5, Unity 2017, and Unity 2018

eBook
R$80 R$187.99
Paperback
R$233.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering UI Development with Unity

Canvases, Panels, and Basic Layouts

Canvases are the core of all Unity UIs. Every single UI element must be included within a Canvas for it to be able to render within a scene. This chapter covers all that you need to create basic UI in Unity.

It's important to start focusing on setting up a UI that will scale at multiple resolutions and aspect ratios early on, as trying to do so later will cause a lot of headache and extra work. This chapter focuses on creating a UI that scales appropriately.

In this chapter, we will discuss the following topics:

  • Creating UI Canvases and setting their properties
  • Creating UI Panels and setting their properties
  • Using the Rect Tool and Rect Transform component
  • Properly setting anchor and pivot points
  • How to create and lay out a basic HUD
  • How to create a background image
  • How to set up a basic pop-up menu
...

UI Canvas

Every UI element you create must be a child of a UI Canvas. To see a list of all UI elements you can create within Unity, select Create | UI from the Hierarchy window, as shown in the following screenshot:

Every one of the UI items highlighted in the preceding screenshot are renderable UI items and must be contained within a Canvas to render. If you try to add any of those UI elements to a scene that does not contain a Canvas, a canvas will automatically be added to the scene, and the item you attempted to create will be made a child of the newly added Canvas. To demonstrate this, try adding a new UI Text element to an empty scene. You can do so by selecting Create | UI | Text.

This will cause three new items to appear in the Hierarchy list: Canvas, Text, and Event System, where the Text is a child of the Canvas.

Now that you have a Canvas in your scene, any new UI...

UI Panel

The main function of UI Panels is to hold other UI elements. You can create a Panel by selecting Create | UI | Panel. Its important to note that there is no Panel component. Panels are really just GameObjects that have Rect Transform, Canvas Renderer, and Image components. So, really, a UI Panel is just a UI Image with a few properties predefined for it.

By default, Panels start with the Background image (which is just a grey rounded rectangle) as the Source Image with medium opacity. You can replace the Source Image with another image or remove the image entirely.

Panels are very useful when you are trying to ensure that items scale and are appropriately relative to each other. Items that are contained within the same Panel will scale relative to the Panel and maintain their relative position to each other in the process.

We will look at the Image component more thoroughly...

Rect Transform

Each UI element has a Rect Transform component. The Rect Transform component works very similarly to the Transform component and is used to determine the position of the object on which it is attached.

Rect Tool

Any of the Transform tools can be used to manipulate UI objects. However, the Rect Tool allows you to scale, move, and rotate any object by manipulating the rectangle that encompasses it. While this tool can be used with 3D objects, it is most useful for 2D and UI objects.

  • To move an object with the Rect Tool, select the object and then click and drag inside the rectangle.
  • To resize an object, hover over the edge or corner of an object. When the curse changes to arrows, click and drag to resize the...

Anchor and Pivot Point

Every UI object has a set of Anchor Handles and a Pivot Point. These objects used together will help ensure that your UI is positioned appropriately and scales appropriately if the resolution or aspect ratio of your game changes.

The Anchor Handles are represented by four triangles in the form of an X, as shown in the following diagram:

The Anchors can be in a group together forming a single Anchor, as shown in the preceding diagram, or they can be split in to multiple Anchors, as follows:

The Anchors will always form a rectangle. So, the sides will always line up.

The Rect Transform has properties for Anchor Min and Anchor Max points. These represent the position of the Anchor Handles relative to the parent's Rect Transform, as percentages. So, for example, a 0 in an x value represents all the way to the left, and a 1 represents all the way to the...

Canvas Group component

You can add a Canvas Group component to any UI object. It allows you to adjust specific properties of the UI object it is attached to and all of its children at once, rather than having to adjust these properties individually. You can add a Canvas Group component to any UI object by selecting Add Component | Layout | Canvas Group (you can also just search for Canvas Group) from the UI object's Inspector.

You can adjust the following properties using a Canvas Group component:

  • Alpha: This is the transparency of the UI objects within the Canvas Group. The number is between 0 and 1 and represents a percentage of opaqueness; 0 is completely transparent, while 1 is completely opaque.
  • Interactable: This setting states whether or not the objects within the group can accept input.
  • Blocks Raycast: This setting determines if the objects within the group will...

Introducing UI Text and Image

It's kind of hard to make any UI examples without using text or images. So, before we cover examples of that discuss layout, let's first look at the basic properties of UI Text and UI Images. UI Text and UI Images are discussed more thoroughly in Chapter 6, Text, Images, and TextMesh Pro-Text.

When you create a new Text object using Create | UI | Text, you will see that it has a Text Component.

You can change the displayed text by changing the words in the New Text box. In Chapter 6, Text, Images, and TextMesh Pro-Text, we'll take a closer look at the individual properties of the Text component, but, for now, it should be fairly obvious what most of the properties do.

When you create a new Image object using Create | UI | Image, you will see that it has an Image component.

Remember that a Panel is essentially an Image, but with a...

Examples

Now let's jump into some examples! We'll be creating a layout for a basic heads-up-display (HUD) and a background image that stretches with the screen and scales at multiple resolutions.

Before we begin setting up our UI, let's set up our project and bring in the art assets we will need.

We'll begin by setting up our project:

  1. Create a new Unity Project and name it Master Unity UI Project. Create it in the 2D mode.
We're selecting 2D Mode because it will make importing our UI sprites a lot easier. When in 2D Mode, all images import as Sprite (2D and UI) images rather than Texture images, as they do in 3D Mode. You can change to 3D Mode at any time by navigating to Edit | Project Settings | Editor and changing Mode to 3D.
  1. Create three new folders named Scenes, Scripts, and Sprites:
You don't need the Editor folder, but, if you'd...

Summary

Wow! This chapter was intense! There was a lot to cover, as this chapter set the groundwork that will be used throughout the rest of this book.

In this chapter, we discussed the following topics:

  • Creating UI Canvases and setting their properties
  • Creating UI Panels and setting their properties
  • Using the Rect Tool and Rect Transform component
  • Properly setting anchor and pivot points
  • Creating and laying out a basic HUD
  • Creating a background image
  • Setting up a basic pop-up menu

The next chapter will cover how to create different automatic layouts that will let us line up our UI in grids.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Develop a game UI with both technical and aesthetic considerations
  • Use all the UI elements provided by Unity's UI system
  • Step-by-step examples of creating user interface components in the top game genres

Description

A functional UI is an important component for player interaction in every type of video game. Along with imparting crucial statistical information to the player, the UI is also the window through which the player engages with the world established by the game. Unity's tools give you the opportunity to create complex and attractive UIs to make your game stand out. This book helps you realize the full potential of Unity's powerful tools to create the best UI for your games by walking you through the creation of myriad user interface components. Learn how to create visually engaging heads-up-displays, pause menus, health bars, circular progress bars, animated menus, and more. This book not only teaches how to lay out visual elements, but also how to program these features and implement them across multiple games of varying genres. While working through the examples provided, you will learn how to develop a UI that scales to multiple screen resolutions, so your game can be released on multiple platforms with minimal changes.

Who is this book for?

This book is for anyone keen to improve their games via a great user interface with Unity's UI system. If you're looking for a book that explains how to develop specific user interfaces or that thoroughly explains how each of the individual Unity components work, this book is for you.

What you will learn

  • Design principles and patterns for laying out elements in your UI
  • Techniques that allow your UI to scale appropriately in different resolutions
  • How to use automatic layouts to streamline your UI building process
  • Properties of the Event System and how to appropriately hook events to your UI elements
  • Access the components and properties of UI elements via code
  • Implement all of Unity s built-in UI elements as well as those provided by TextMeshPro
  • Develop key UI components that are popularly used in multiple game genres
  • Add visual flare to user interfaces with the use of animation and particle effects
  • Create a UI that displays in the Screen Space as well as World Space
Estimated delivery fee Deliver to Brazil

Standard delivery 10 - 13 business days

R$63.95

Premium delivery 3 - 6 business days

R$203.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2018
Length: 468 pages
Edition : 1st
Language : English
ISBN-13 : 9781787125520
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Brazil

Standard delivery 10 - 13 business days

R$63.95

Premium delivery 3 - 6 business days

R$203.95
(Includes tracking information)

Product Details

Publication date : Apr 30, 2018
Length: 468 pages
Edition : 1st
Language : English
ISBN-13 : 9781787125520
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 813.97
Unity 2018 Shaders and Effects Cookbook
R$306.99
Unity 2018 Artificial Intelligence Cookbook
R$272.99
Mastering UI Development with Unity
R$233.99
Total R$ 813.97 Stars icon

Table of Contents

11 Chapters
Designing User Interfaces Chevron down icon Chevron up icon
Canvases, Panels, and Basic Layouts Chevron down icon Chevron up icon
Automatic Layouts Chevron down icon Chevron up icon
The Event System and Programming for UI Chevron down icon Chevron up icon
Buttons Chevron down icon Chevron up icon
Text, Images, and TextMesh Pro-Text Chevron down icon Chevron up icon
Masks and Other Inputs Chevron down icon Chevron up icon
Animations and Particles in the UI Chevron down icon Chevron up icon
World Space UI Chevron down icon Chevron up icon
Mobile-Specific UI Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(4 Ratings)
5 star 75%
4 star 0%
3 star 25%
2 star 0%
1 star 0%
POE May 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This compressive book is the only reference you will need for designing and implementing quality User Interfaces in Unity. While this book is targeted to game developers, it is also valuable to designers and developers creating situations and other solutions in Unity.The author does an excellent job explaining concepts and considerations before demonstrating the “how-to” of implementation. Truly, this is the best Unity UI book on the market and the only one you will need.
Amazon Verified review Amazon
Carlo R. Montoya Feb 21, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've read Ashley's Mastering Unity 2D Game Development and that book didn't disappoint.This book - despite having a handful of typo errors - also didn't disappoint. It has almost everything you need to code pro-level UI behaviors (find good art assets or hire an artist do make them to put icing on the cake).I enjoyed the example integrating a UI with a particle system.I do wish there was an explanation why the billboard code works especially the use of 2 in 2 * transform.position. I played around with it and it seems it controls the rotation of the canvas in the x-axis.
Amazon Verified review Amazon
Amazon Customer Nov 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Has a lot of info, and goes over any basics that you could want to know. I started using unity a long time ago, but never actually looked into how to properly use the canvas, which this book was a life saver. Must read for any professional unity programer.
Amazon Verified review Amazon
Patrick Wade Runyan Sep 12, 2020
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This isn't a bad book and it did help me get some hands-on practice with the visual elements in Unity.However, I consider time dedicated to the EventSystem or older forms of Input collection to be dated.All else being equal, I would recommend a book that delves straight into UI using the new 2019 Input System. As of the time of this review, version 1.0.0 is now available and it is so much better than the default Event System (covered in this book) or the legacy Input API. Unfortunately, I don't think anyone has made a good book covering it yet, but I would look for one soon.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela