Book Image

Learning NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

Learning NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (17 chapters)
Learning NGUI for Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

This book is a beginner's guide to the Next-Gen UI kit, also known as NGUI. You might have heard about this Unity 3D plugin; it is popular among developers for its easy-to-use and effective What You See Is What You Get workflow.

NGUI provides built-in components and scripts to create beautiful 2D and 3D UIs for your projects, with most of the work done inside the editor.

With this book, you will gather the necessary knowledge to create functional UIs. The 10 practical chapters of this book will guide you through the creation of both a main menu and a simple 3D game, which are compatible with both PC and mobile platforms.

What this book covers

Chapter 1, Getting Started with NGUI, describes NGUI's functionalities and workflow. You will then import the plugin, create your first UI system, and study its structure.

Chapter 2, Creating NGUI Widgets, introduces you to your first widget and explains how to configure it. Then, it covers how to create a main menu.

Chapter 3, Enhancing Your UI, explains how to create draggable windows and scrollable text and use anchors intelligently. It also covers animations and localization with NGUI.

Chapter 4, C# with NGUI, introduces C# event methods used to create tooltips, tweens, and more through code, along with making the UI persistent through different scenes.

Chapter 5, Atlas and Font Customization, explains how to customize your UI using your own sprites and fonts, and we will modify the entire main menu's appearance.

Chapter 6, The In-game User Interface, introduces in-game 2D interface elements, such as displaying life gauges and player names above them, along with interactive buttons.

Chapter 7, 3D User Interface, covers how to add 3D widgets in the environment, such as a pause menu painted on the ground affected by the world's lighting effects.

Chapter 8, Going Mobile, teaches you how to prepare the project and fix mobile platform-specific issues so that our game runs perfectly on Android devices.

Chapter 9, Screen Sizes and Aspect Ratios, explains how you can ensure you'll have a beautiful user interface on all mobile devices even if they have different screen sizes.

Chapter 10, User Experience and Best Practices, discusses user interface design guidelines, user experience, and testing to help you improve your system's efficiency.

What you need for this book

In order to follow this book, you will need the Unity 3D software available here at http://unity3d.com/unity/download.

You might have any version of Unity, but I recommend at least version 4.5; just the Add Component button and copy and paste component features will buy you some time, along with the easy inspector tooltip display through code.

You must be familiar with Unity's basic workflow; the words GameObjects, Layers, and Components should not be a secret to you.

Concerning coding skills, all the code is available here and explained with comments on each line, so if you are not familiar with it, you will still be able to understand it.

While working with this book, you will be able to create your own sprites. If you do not want or cannot create these assets by yourself, don't worry; the ones I have created for this book will be available to download with a link.

You will also need the NGUI plugin for Unity by Tasharen Entertainment. I used the latest version at the time I wrote this book, which is NGUI v3.7.6. You may buy the plugin directly on the Unity Asset Store or with the Buy button at the bottom of this page: http://www.tasharen.com/?page_id=140.

For Chapter 8, Going Mobile, an Android device is recommended but not necessary.

Who this book is for

Whether you are a beginner starting to work with Unity 3D, an intermediate developer, or a professional developer searching for an effective UI solution, this book is for you.

Maybe you have worked on games or apps for PC, console, or mobile platforms, but you're struggling with Unity's built-in UI system to create your game's interfaces and menus. If so, this is where you should be.

Once you have finished this book, you will discover that building a user interface can be easy, fast, and fun!

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 hierarchy / project view paths are shown as follows: "Select our InGame2DUI | HoldFeedback | Sprite GameObject."

A block of code is set as follows:

// Method that cancels the movement request
public void CancelMovementRequest()
{
  // Cancel the movement request
  validMoveRequest = false;
}

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

  // Set filled sprite's fill amount to zero
  holdFeedback.fillAmount = 0;
  // Show the hold feedback sprite
  holdFeedback.enabled = true;

Any command-line input or output is written as follows:

adb logcat –s Unity

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: "You can edit Unity input axes at any time by navigating to Edit | Project Settings | Input."

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 for all Packt books you have purchased from your account at http://www.packtpub.com. 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.

Downloading the color images of this book

We also provide you 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: http://www.packtpub.com/sites/default/files/downloads/1453OT_ColorImages.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 would 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

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.