NGUI for Unity
()
About this ebook
If you are a Unity 3D developer looking forward to learn NGUI for Unity, then this book is for you. Prior knowlege of C# scripting is expected. Additional knowledge of Unity 3D Editor, GameObject and creating/adding scripts to GameObject would be beneficial; however, no prior knowledge of NGUI is required.
Related to NGUI for Unity
Related ebooks
Building an RPG with Unity 5.x Rating: 0 out of 5 stars0 ratingsUnity 5.x By Example Rating: 0 out of 5 stars0 ratingsMastering Unity Scripting Rating: 0 out of 5 stars0 ratingsExtending Unity with Editor Scripting Rating: 0 out of 5 stars0 ratingsBuilding an FPS Game with Unity Rating: 0 out of 5 stars0 ratingsUnity Game Development Blueprints Rating: 0 out of 5 stars0 ratingsOuya Unity Game Development Rating: 0 out of 5 stars0 ratingsLearning C# by Developing Games with Unity 2019 - Fourth Edition: Code in C# and build 3D games with Unity, 4th Edition Rating: 0 out of 5 stars0 ratingsUnity Game Development Scripting Rating: 0 out of 5 stars0 ratingsSFML Blueprints Rating: 0 out of 5 stars0 ratingsHTML5 Game Development with GameMaker Rating: 0 out of 5 stars0 ratingsGameMaker Essentials Rating: 0 out of 5 stars0 ratingsGetting Started with Unity 5 Rating: 5 out of 5 stars5/5Unity Animation Essentials Rating: 0 out of 5 stars0 ratingsMobile Game Design Essentials Rating: 0 out of 5 stars0 ratingsBuilding Android Games with Cocos2d-x Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Intermediate): Unity from Zero to Proficiency, #3 Rating: 2 out of 5 stars2/5Unity 5 for Android Essentials Rating: 4 out of 5 stars4/5Android Game Programming by Example Rating: 0 out of 5 stars0 ratingsGodot from Zero to Proficiency (Beginner): Godot from Zero to Proficiency, #2 Rating: 5 out of 5 stars5/5Beginning Unreal Game Development: Foundation for Simple to Complex Games Using Unreal Engine 4 Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Beginner): Unity from Zero to Proficiency, #2 Rating: 5 out of 5 stars5/5Swift 2 Design Patterns Rating: 0 out of 5 stars0 ratingsGodot from Zero to Proficiency (Intermediate): Godot from Zero to Proficiency, #3 Rating: 5 out of 5 stars5/5Instant HTML5 2D Platformer Rating: 0 out of 5 stars0 ratingsBuilding an RPG with Unreal Rating: 0 out of 5 stars0 ratingsOpenGL Game Development By Example Rating: 0 out of 5 stars0 ratingsMastering Android Game Development Rating: 0 out of 5 stars0 ratings
Programming For You
Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Coding with JavaScript For Dummies Rating: 0 out of 5 stars0 ratingsBeginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5C# 7.0 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsPython Data Structures and Algorithms Rating: 5 out of 5 stars5/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5Narrative Design for Indies: Getting Started Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5
Reviews for NGUI for Unity
0 ratings0 reviews
Book preview
NGUI for Unity - Charles Bernardoff
Table of Contents
NGUI for Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with NGUI
What is NGUI?
UnityGUI versus NGUI
Atlases
Events
Localization
Shaders
Importing NGUI
Creating your UI
UI Wizard
Window
Parameters
Separate UI Layer
Your UI structure
UI Root (2D)
Parameters
Camera
Parameters
Anchor
Parameters
Panel
Parameters
Summary
2. Creating Widgets
Creating our first widget
Widget Wizard
Selecting an atlas
Creating a widget from a template
Transforming widgets
Moving widgets
Rotating widgets
Scaling widgets
Common widget parameters
Sprites
Sliced sprites
Tiled sprites
Filled sprites
Labels
Parameters
Creating the title bar
Buttons
Parameters
The play and exit buttons
Text input
Parameters
Creating a nickname box
Slider
Parameters
Creating a volume slider
Toggle
Parameters
Creating a sound toggle
Popup list
Parameters
Creating a difficulty selector
Summary
3. Enhancing your UI
NGUI components
The draggable panel
Parameters
Dragging the MainMenu
The drag-and-drop system
Powers selection
Draggable items container
Draggable items
The drop surface
Prefab instantiated on drop
Handling an invalid drop
Replacing the current item
Removing the current item
Animations with NGUI
Smooth powers apparition
Clipping to hide options
Scrollable text
Localization system
Localization files
Localization component
Language selection box
Localizing a Label
Summary
4. C# with NGUI
Events methods
Creating a tool tip
The tool tip reference
Showing the tool tip
Tween methods
Main menu apparition
Simple Tween
Smooth Tween
Using keys for navigation
Error notification
Saving the nickname
Sending messages
Forwarding an event
Summary
5. Building a Scrollable Viewport
Preparing the Game scene
The scrollable viewport
Draggable background
Linking scroll bars
Keyboard scrolling
Creating draggable barriers
The BarrierObject prefab
Dropping a barrier on Viewport
Creating an ActiveBarrier prefab
The ActiveBarrier prefab
Instantiating the ActiveBarrier prefab
Barrier's building process
Forwarding events to viewport
BarrierObject cooldown
Cooldown implementation
BarrierObject smooth apparition
The barrier availability tool tip
Summary
6. Atlas and Font Customization
The Atlas prefab
Creating a new Atlas
Adding sprites to Atlas
Simple sprites
Adding sprites to Atlas
Available powers icons
Selected powers icons
Sliced sprites
Adding a sprite to Atlas
Configuring a sliced sprite
The Main Menu window
Tiled sprites
Adding a font
Exporting a font using BMFont
Creating a font in Unity
Assigning a new font to Label
Customizing the MainMenu
Summary
7. Creating a Game with NGUI
Enemy spawning
Creating the enemies container
Creating the Enemy prefab
Creating the enemy spawn controller
Forwarding events to viewport
Handling enemy collisions
Collisions with active barriers
Colliding with the bottom of the screen
Healthbar
The EndOfScreen widget
Creating self-destruct code
The hacking slider
Self-destruct code
Assigning code to an enemy
The hacking process
Handling player input
Summary
Index
NGUI for Unity
NGUI for Unity
Copyright © 2014 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2014
Production Reference: 1170114
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-866-7
www.packtpub.com
Cover Image by Aniket Sawant (<[email protected]>)
Credits
Author
Charles Bernardoff
Reviewers
Adrián del Campo
Andreas Grech
Philip Pierce
Abdelrahman Saher
Acquisition Editor
Subho Gupta
Commissioning Editor
Shaon Basu
Technical Editors
Shubhangi H. Dhamgaye
Rohit Kumar Singh
Copy Editors
Roshni Banerjee
Aditya Nair
Shambhavi Pai
Project Coordinator
Joel Goveya
Proofreader
Simran Bhogal
Indexer
Hemangini Bari
Production Coordinator
Nitesh Thakur
Cover Work
Nitesh Thakur
About the Author
Charles Bernardoff has a bachelor's degree in Game Design and Level Design delivered by ISART Digital, a video games school located in Paris, France.
With four years of experience as game designer, level designer, and C# scripter at Cyanide Studio, Playsoft, and Airbus, Charles has worked on the PC versions of Blood Bowl, Dungeonbowl, and Confrontation. He has also worked on Unity and Flash mobile games, such as Space Run 3D, Oggy, and Psycho Gnomes.
He now works as Game Designer and Unity developer on PC and mobile Serious Games at Airbus.
I wish to personally thank Abdelrahman Saher, Usuario, and Andreas Grech, great reviewers who helped in making the book better. I also want to thank my family and friends for their great support while I was working on this project.
About the Reviewers
Adrián del Campo studied Computer Science at the Antonio de Nebrija University, specializing in server and DB administration. After a few years of working as a sysadmin and Java programmer, he decided to move to the game industry, pursuing a master's degree in Game Development at the Universidad Complutense. After that, he worked in top companies such as Pyro Studios and is currently working in Mediatonic Ltd. as a video game programmer. You can find him on twitter as @acampoh.
Andreas Grech is a Malta-based programmer and coffee aficionado. With over seven years of professional experience in the software development industry, he has worked on desktop applications, web experiences, and video games.
After earning his degrees from MCAST and the Fraunhofer-Gesellschaft and later working in Oslo, Norway, for a number of years, he settled back in Malta to start working in the video games industry, professionally with the Unity game engine.
Since then, Andreas has written a number of video games in Unity, including Typocalypse 3D, a web-based typing-shooter game, and No Photos, Please!, a local two-player stealth party video game. He also maintains a technical blog about his programming experiences at http://blog.dreasgrech.com.
Philip Pierce is a software developer with 20 years' experience in mobile, web, desktop, and server development; database design and management; and game development. His background includes creating AI for games and business software, converting AAA games between various platforms, developing multithreaded applications, and creating patented client/server communication technologies.
Philip has won several hackathons, including Best Mobile App at the AT&T Developer Summit 2013, and a runner-up for Best Windows 8 App at PayPal's Battlethon Miami. His most recent project was converting Rail Rush and Temple Run 2 from the Android platform to Arcade platforms.
Philip's portfolios can be found at http://www.rocketgamesmobile.com and http://www.philippiercedeveloper.com.
Abdelrahman Saher graduated with a B.Sc. in Computer Science in 2012. After graduation, Abdelrahman worked with the video game company Every1Plays, where he participated in the programming of a couple of mobile games. Later, in 2013, Abdelrahman moved into the challenging role of lead programmer with the video game company AppsInnovate. Apart from his work, Abdelrahman recently started his own start-up video game company, Robonite.
I would like to thank my family and friends for helping me and always being there for me.
www.PacktPub.com
Support files, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print and bookmark content
On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Preface
This book is dedicated to beginners of the Next-Gen UI kit, also known as NGUI. You may have heard about this Unity 3D plugin; it is popular amongst developers for its easy-to-use and effective WYSIWYG workflow.
NGUI provides built-in components and scripts to create beautiful user interfaces for your projects, with most of the work happening inside the editor.
Through this book, you will gather the necessary knowledge to create interesting user interfaces. The seven chapters of this book are practical and will guide you through the creation of both a main menu and a 2D game.
What this book covers
Chapter 1, Getting Started with NGUI, describes NGUI's functionalities and workflow. We will then import the plugin and create our first UI system and study its structure.
Chapter 2, Creating Widgets, introduces us to our first widget and explains how we can configure it. It then explains how to create a main menu using the Widget template
Chapter 3, Enhancing Your UI, explains the drag-and-drop system and how to create draggable windows. It also covers the use of animations, scrollable text, and localization with NGUI.
Chapter 4, C# with NGUI, introduces C# event methods and advanced code-oriented components that will be used to create tool tips, notifications, and Tweens through code.
Chapter 5, Building a Scrollable Viewport, introduces us to an interactive fullscreen-scrolling viewport using scroll bars, keyboard arrows, and draggable items.
Chapter 6, Atlas and Font Customization, explains how you can customize your UI using your own sprites and fonts; this will enable us to modify the appearance of our entire main menu.
Chapter 7, Creating a Game with NGUI, covers game features, such as spawning mobile enemies, handling player input, and detecting collisions between widgets to create a game.
What you need for this book
In order to follow this book, you will need the Unity 3D software available at http://unity3d.com/unity/download.
You may use any version of Unity, but I recommend the 4.x cycle. Just the Add Component button and copy-paste component features will buy you some time.You must be familiar with Unity's basic workflow; the words GameObjects, Layers, and Components should not be a secret for you.
All the code pertaining to coding skills are available here and explained with comments on each line. So if you are not familiar with them, you will still be able to understand it.
While working with this book, we will create our own Sprites. If you do not want to or