Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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

Arrow left icon
Profile Icon Dr. Ashley Godbold
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (4 Ratings)
Paperback Apr 2018 468 pages 1st Edition
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Dr. Ashley Godbold
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (4 Ratings)
Paperback Apr 2018 468 pages 1st Edition
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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

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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
$19.99 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
$199.99 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 $5 each
Feature tick icon Exclusive print discounts
$279.99 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 145.97
Mastering UI Development with Unity
$41.99
Unity 2018 Artificial Intelligence Cookbook
$48.99
Unity 2018 Shaders and Effects Cookbook
$54.99
Total $ 145.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 included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.

Modal Close icon
Modal Close icon