Book Image

Unity3D UI Essentials

By : Simon Jackson
Book Image

Unity3D UI Essentials

By: Simon Jackson

Overview of this book

<p>Unity is a powerful cross-platform development engine that provides rich framework to create 2D and 3D apps or games. Through Unity3D, users are able take master the complexities of game development with ease, including animations, physics, renderings, shaders, scripting and now, Unity have released a new and advanced system to cope with the UI demands for modern applications and games.</p> <p>Unity 3D UI Essentials is a complete walk-through of the new UI system in Unity V4 and beyond (including Unity 5). This fast-paced practical tutorial provides you with in depth details of the new UI controls and layouts that can be used to create stunning and multiresolution UI.</p> <p>Venture forth into the highly componentized and advanced UI system, covering new features such as responsive designs and layouts. Also you get to deep-dive into the scripting side of the UI system as Unity has made the entire framework open source, giving free access to the source code of the new UI system to all developers.</p> <p>So get ready for a wild ride into the new Unity3D UI system and set your course for awesome!</p>
Table of Contents (14 chapters)

Preface

A new era has dawned, and Unity Technologies have taken a big, bold step. Not only have they delivered on some big promises for an all new and improved UI system for Unity projects, but they have also made the source for the new UI completely open source, giving everyday developers access to the inner workings of the new UI.

These are bold steps indeed. Many felt that the new UI wouldn't live up to the dream that was sold, as it had been years since they announced it was coming. Delays and rewrites made it look like it was never going to happen, leaving developers with either having to live with the existing legacy GUI or pay for some of the more advanced GUI systems on the asset store (such as NGUI).

Now, after a long and highly deliberated beta program, the new UI system is finally upon us. In some areas, it meets our expectations; in some, it falls a bit short (however, this is only the beginning). In other areas however, it has gone far beyond.

Throughout this title, we will peel back the layers of all this new technology to understand what each component does, how it fits together, and how to use it to build a fantastic new UI in our projects. Each chapter builds upon the last, to arm you (the reader) with all the knowledge required to assemble your UI within your projects. You will not just build on screen menus and options, but to embed UI elements within your 3D game world.

Not only have Unity released the new UI system, they have also given every developer access to the source that builds the UI, allowing you to better understand how things are built and enable you to extend the existing controls or even build your own. If you are feeling adventurous, you can even submit fixes or new features back to Unity for them to include within Unity itself.

Finally, we can now build what we want, how we want and best of all, it's completely free and available with the Free license for Unity. All hail and rejoice!

Now what are you waiting for? Pack up your towel, brew a freshly hot cup of tea, crack open this guide, and start exploring the all new universe of UI.

What this book covers

Chapter 1, Looking Back, Looking Forward, is a retrospective look at what Unity3D had to offer prior to 4.6 and an overview of what 4.6 and beyond brings to the table, including a high-level overview of all the new UI features.

Chapter 2, Building Layouts, covers the core elements of the new Unity UI system, the Canvas and Rect Transforms. These elements are the foundations of the new Unity UI system.

Chapter 3, Control, Control, You Must Learn Control, Unity UI introduces a heap-load of new UI controls to suit just about any UI need, from buttons and checkboxes to entire scrollable areas and layout masks. Here, we will delve deep into how to make the most of all the controls available.

Chapter 4, Anchors Away, provides a detailed walk-through of how to make the most of the new Unity UI anchor system and build responsive layouts/designs.

Chapter 5, Screen Space, World Space, and the Camera, Here we finally delve into one of the most highly anticipated parts of the new UI system: the ability to easily build perspective UI layouts and add UI elements as 3D objects within a scene.

Chapter 6, Working with the UI Source, looks at all the coding behind the UI framework and explores the new Event System and UnityEvent frameworks. The chapter finishes with a walk-through, the open source project for the UI system, allowing you to see just about every line of code Unity has written for the new UI.

Appendix, The 3D Scene Sample, talks about a flashy 3D demo scene, which was discussed in Chapter 5, Screen Space, World Space, and the Camera, to show off the UI. Because this wasn't the focus of the book, it was added as an optional appendix that you could follow if you wish. The instructions are also available online and as a downloadable package to enable developers of all levels to make use of it.

What you need for this book

  • Unity3D V4.6+

  • Visual Studio 2012 (Express, Pro, or higher); optional but recommended

Who this book is for

This book is for anyone with a solid understanding of Unity's core functionality and a decent grasp of C# scripting in Unity (although not required for just the core editor portions of the new Unity UI system). With this book, you'll be well placed to take advantage of the new UI feature set.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "For standards stake, you should add scripts into a folder called Scripts and scenes into a folder called Scenes."

A block of code is set as follows:

void OnGUI() {
  GUI.Label(new Rect(25, 15, 100, 30), "Label");
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public Texture2D myTexture;
void Start() {
  myTexture = new Texture2D(125, 15);
}
void OnGUI() {
  GUI.DrawTexture(new Rect(325, 15, 100, 15), myTexture, ScaleMode.ScaleToFit,true,0.5f);
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "With the new Unity UI system, you can define several layout groups."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Additionally, the author has provided a support forum for the book. This forum provides direct support from the author on your queries and any forthcoming announcements regarding the title. You can find this forum at http://bit.ly/Unity3DUIEssentialsForums.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/3617OS.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.

Additionally you can post questions directly to the author about the content of the title on the book's support forum at http://bit.ly/Unity3DUIEssentialsForums.