Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
NGUI for Unity
NGUI for Unity

NGUI for Unity: The NGUI plugin for Unity makes user interfaces so much more efficient and attractive. Learn all about it in this step-by-step tutorial that includes lots of practical exercises, including creating a fun 2D game.

Arrow left icon
Profile Icon Charles Bernardoff (EURO)
Arrow right icon
€8.99 €22.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9 (14 Ratings)
eBook Jan 2014 182 pages Edition
eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Charles Bernardoff (EURO)
Arrow right icon
€8.99 €22.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9 (14 Ratings)
eBook Jan 2014 182 pages Edition
eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

NGUI for Unity

Chapter 2. Creating Widgets

In this chapter, we will create our first sprite widget and understand how it works. Then we will create one sample of each important widget template, and analyze their corresponding parameters so that you know how to create and configure them.

At the end of this chapter, we will have a functional main menu with most of NGUI's widgets.

Creating our first widget


We will create our first sprite widget to display our main menu's background window. In order to do that easily, NGUI has a Widget Wizard with a few templates for us.

Widget Wizard

The Widget Wizard can be opened by navigating to NGUI | Open | Widget Wizard. It will look like the following screenshot:

As you can see in the previous screenshot, to create a widget, you require Atlas and Font to be configured. As said in Chapter 1, Getting Started with NGUI, an atlas is a large texture containing the sprites that you need to create your UI. For the rest of this chapter, we will use the default atlas named SciFi Atlas , which is included in the plugin.

Selecting an atlas

Let's select our default SciFi atlas, which contains the necessary sprites, as follows:

  1. In the Project view, navigate to Assets | NGUI | Examples | Atlases | SciFi.

  2. Drag-and-drop the prefab SciFi Atlas.prefab in the Atlas field.

  3. Drag-and-drop the prefab SciFi Font – Header.prefab in the Font field.

We have...

Sprites


We have created our first sprite and understood how to move, rotate, and change its dimensions. We actually scaled it up massively compared to its original size. But this 15 x 15 sprite has something special.

If you select the Sprite (Dark) GameObject, you will see it has four dotted lines inside the Preview window in the Inspector view. This means it's a sliced sprite:

Sliced sprites

A sliced sprite is an image divided in nine sections, making it resizable while conserving its corners' proportions. Sliced sprites may be scaled as you wish—they still look beautiful.

Since Sprite (Dark) is a 9-slice sprite, we must tell our UISprite component to treat it as such. Perform the following steps to do so:

  1. Select the Sprite (Dark) GameObject.

  2. Click on the drop-down menu next to its Sprite Type field.

  3. Select Sliced.

Notice how the sprite looks good now—it's not stretched anymore!

Note

The Fill Center parameter allows you to only show the sprite's borders and leave only transparency inside.

Even though...

Labels


Labels are used to display text on the screen with a specific font as shown in the following screenshot:

Let's create a label widget with the following steps:

  1. Select the Panel GameObject.

  2. Navigate to NGUI | Open | Widget Wizard.

  3. Select the Label template.

  4. We have already selected a font; it will be used for this label.

  5. Click on the Add To button.

A new label has been added to the panel and placed at the center of the screen.

Parameters

With Label selected, the UILabel parameters are shown in the Inspector view. They are as follows:

  • Text: This is a large textbox that lets you type the text to be displayed.

  • Overflow: This offers four different behaviors for the widget when the text is larger than the label's Dimensions. The four behaviors are as follows:

    • Shrink Content: This shrinks the text in order to fit

    • Clamp Content: This ensures overflow will never happen

    • Resize Freely: This resizes to display all the content and overflow

    • Resize Height: This resizes height only—column style

  • Encoding: This...

Buttons


With NGUI, buttons are easy to create and configure.

Let's create our first one by performing the following steps:

  1. Select the Panel GameObject.

  2. Create a new child with Alt + Shift + N and perform the following steps:

    1. Rename it as Buttons. It will be our buttons container.

  3. Navigate to NGUI | Open | Widget Wizard and perform the following steps:

    1. Select the Button Template.

    2. For the Background field, select the sprite named Button.

  4. With the Buttons GameObject selected, click on the Add To button.

A button has just been created and centered on the screen. If you look at the Hierarchy view, you will see that a button is composed of a container GameObject named Button and two children: a Background sprite and Label. That's how NGUI works; templates are simply assembled components and widgets. If you wanted to, you could build a button from scratch using the right components on empty GameObjects.

Click on the Play button. You can see that hover and click are already set! Turn off the Play mode, select...

Text input


Now we will learn how to add a text input to create a nickname box. Perform the following steps to do so:

  1. Select the Panel GameObject and create a new child with Alt + Shift + N. Then rename this new child as Nickname. It will be our nickname box container.

  2. Navigate to NGUI | Open | Widget Wizard.

    1. From the Project view, navigate to NGUI | Examples | Atlases | SciFi.

    2. Drag the SciFi Font – Normal prefab into the Font field.

    3. Select the Input template.

    4. Set Sprite (Dark) as the Background parameter.

  3. With the Nickname GameObject selected, click on the Add To button.

A new widget named Input has been added to the scene.

Parameters

An Input GameObject has been created. Let's look at its Inspector parameters:

  • Input Label: This is the text label that is to be used for this input.

  • Inactive Color: This is the text color while the text is not selected.

  • Active Color: This is the text color while the text is being edited.

  • Default Text: This is either Blank or with the label's default text. Blank will...

Slider


Now let's add a volume slider for the user to move and select his/her volume level.

A slider template is available, enabling you to adjust parameters easily by sliding a thumb along a bar. Perform the following steps to create a volume slider:

  1. Select the Panel GameObject and create a new child with Alt + Shift + N.

  2. Rename that new child as Volume. It will be our volume settings container.

  3. Navigate to NGUI | Open | Widget Wizard and perform the following steps:

    1. Select the Slider template.

    2. Set the Dark Sprite to Empty.

    3. Set the Light Sprite to Full.

    4. Set Highlight to Thumb.

  4. With the Volume GameObject selected, click on the Add To button.

Parameters

A slider has been created. It has 6 parameters as follows:

  • Value: This is the slider's current value, which is between 0 and 1.

  • Steps: This is the number of steps to completely fill or empty the slider.

  • Direction: This is the slider's fill direction, either Horizontal or Vertical.

  • Foreground: This is the sprite used to fill the slider.

  • Thumb: This is...

Toggle


Now that we have a volume slider, let's add an enable/disable sound checkbox, which will turn down the volume to 0 and hide our volume slider.

First, create a toggle widget as follows:

  1. Select the Panel GameObject and create a new child with Alt + Shift + N.

  2. Rename that new child as Sound. It will be our sound toggle container.

  3. Navigate to NGUI | Open | Widget Wizard and perform the following steps:

    1. Select Toggle as Template.

    2. Select the Dark Sprite as Background.

    3. Select the X Sprite as Checkmark.

    4. With the Sound container selected, click on the Add To button.

A checkbox with a label has just been created as shown in the following screenshot:

Parameters

Select our new Toggle GameObject. Let's look at the UIToggle's Inspector parameters:

  • Group: This is the toggle's group. Toggles of the same group will act as radio buttons; only one of them can be checked at once.

  • Start State: This defines in which state the toggle will be at the start.

  • Animation: This is the animation that will play when the checkbox...

Popup list


We will now learn how to create the popup list, see its parameters, and create a difficulty selector for our game.

  1. Select the Panel GameObject and create a new child with Alt + Shift + N.

  2. Rename that new child as Difficulty. It's our difficulty box container.

  3. Navigate to NGUI | Open | Widget Wizard and perform the following steps:

    1. Select Popup List as Template

    2. Select Dark as Foreground.

    3. Select Dark as Background.

    4. Select the Highlight sprite as Highlight.

  4. With our Difficulty GameObject selected, click on the Add To button.

Parameters

A Popup List GameObject has just been created. Let's look at its parameters:

  • Atlas: This is the atlas used for the popup list's sprites.

  • Font: This is the font used for the popup list's options.

  • Text Label: This is the label to update when Popup List changes selection.

  • Options: This is the list of options that will pop up—one per line.

  • Default: This is the option selected at start.

  • Position: You may force the list of options to appear Above or Below the Popup...

Summary


In this chapter, we have learned how to create and configure most of NGUI's widgets—sprites, labels, buttons, text inputs, sliders, toggles, and popup lists.

We now have a main menu with interactive elements. We also used NGUI's notification event system to change variables in code and register the user's choices.

We used UIAnchors and UIStretch components to properly position our widgets—we just have to move each box's background sprite to move the entire element. This is much more effective than having to move each GameObject manually! You should have a main menu that looks like the following screenshot:

Ok, now it is time to enhance our UI experience and make this better. Let's move on to Chapter 3, Enhancing your UI.

Left arrow icon Right arrow icon

What you will learn

  • Download and import NGUI
  • Construct a basic user interface: buttons, sprites, text inputs, lists, sliders, and more
  • Enhance your UI using clipping, draggable panels, content alignment, animations, and localization
  • Use C# with NGUI to save options, implement volume modification, launch animations, and change variables
  • Build a scrollable viewport with a draganddrop system
  • Create tooltips and notifications
  • Add your sprites and fonts to customize your main menu
  • Move elements through code and handle collisions to create a game

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 24, 2014
Length: 182 pages
Edition :
Language : English
ISBN-13 : 9781783558674
Vendor :
Unity Technologies
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 24, 2014
Length: 182 pages
Edition :
Language : English
ISBN-13 : 9781783558674
Vendor :
Unity Technologies
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 108.97
Unity 4.x Game Development by Example: Beginner's Guide
€37.99
NGUI for Unity
€28.99
Unity Character Animation with Mecanim
€41.99
Total 108.97 Stars icon
Banner background image

Table of Contents

7 Chapters
Getting Started with NGUI Chevron down icon Chevron up icon
Creating Widgets Chevron down icon Chevron up icon
Enhancing your UI Chevron down icon Chevron up icon
C# with NGUI Chevron down icon Chevron up icon
Building a Scrollable Viewport Chevron down icon Chevron up icon
Atlas and Font Customization Chevron down icon Chevron up icon
Creating a Game with NGUI Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(14 Ratings)
5 star 42.9%
4 star 21.4%
3 star 28.6%
2 star 0%
1 star 7.1%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Feb 12, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Full Disclosure - I was one of the technical editors for this book.NGUI for Unity provides a step-by-step guide to help you get started using NGUI in Unity. The author explains how each component works and demonstrates proper use of the most commonly used NGUI widgets. The author also walks you through the creation of a 2D game, complete with menu screen and drag-drop elements, as you progress through the book.
Amazon Verified review Amazon
Frida Feb 20, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Im new to NGUI, complete beginner ,The book take you step by step , shows you how to create UI , explain how to use the component with good examples , Widgets , how to create new atlas.Ngui is a great UI system , you can buy it on the Asset store and it's decently wort it.The book is easy to read, very clear , very organized , easy to follow .Now, i understand how to use NGUIi recommend this book book .excellent book !!!Frida
Amazon Verified review Amazon
John Grden Feb 09, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
After interviewing with a few unity3D shops,I was hit with the same question every single time: "do you have NGUI experience?" - to which I replied "no, but I'm sure I can pick it up". They didn't share my optimism :) Enter in NGUI for Unity!What I love about e-books these days is their size and how concise they can be, and this book delivers not only on both counts, but sets you in motion with a very real world example project that covers a great portion of the capabilities of NGUI. Everything from the wizards to widgets to creating atlas' and fonts is covered. The book isn't exhaustive in its explanations but IS thorough in pointing out the features and properties of all the components it covers - which makes it easy to follow along with in the examples.The author gets right to the meat of the matter immediately walking you step by step through the sample project. It helps to have Unity3D experience and you'll have to understand the basics of how unity works with prefabs and code as this book is targeting unity devs looking for a solid UI framework. It IS written in a very practical manner so even a complete beginner could get something out of it.Now, in thinking back about my response to potential clients about just "picking NGUI up", I see how deep the framework really is. It's much more than just a set of UI components, and this book really brought me up to speed in a very short amount if time - excellent work!
Amazon Verified review Amazon
Xavier Valade Mar 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
NGUI is an amazing plugin that makes creating UI and 2D games really easy. This book is THE book to have if you want to discover and master NGUI.It’s perfect for everyone, no matter what their Unity skills are. Beginners can follow clear step by step explanations while professionals can take it to the next level with the advanced features, the complete overview of the different parameters and the many tips.
Amazon Verified review Amazon
Joselyn O'Connor Feb 09, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Finished reading NGUI for Unity a few days ago. Since, I've been skimming through it using it as a reference. I absolutely appreciated that the author was brief and concise in his examples, it made them a most valuable resource while working. It was very easy to read and has given me a much better understanding of NGUI. The resources that are provided with the book are also very well organised, and make for an excellent starting point while tinkering. I definitely recommend this book!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.