You are previewing NGUI for Unity.
O'Reilly logo
NGUI for Unity

Book Description

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.

In Detail

NGUI is an effective plugin for Unity that gives you the power to create beautiful and complex user interfaces while reducing performance costs. It is a powerful UI system and event notification framework for Unity (both Pro and Free) written in C# featuring clean code and a simple, minimalistic approach to everything. You can create a main menu for your game and add sliders, animations, checkboxes, and popup lists, as well as localize your text.

This is an example-oriented, step-by-step, practical tutorial that will guide you through creating a fully functional main menu along with a 2D game. You will acquire the knowledge to create user interfaces for your existing and future PC or mobile games developed with Unity 3D. The book will start by teaching you the basic functions of the tools and how to create a basic UI. Later in the book, you will also learn how to create a much more complex UI.

This book will start by getting you acquainted with NGUI’s workflow and will then gradually take you through building a complex menu and creating a 2D game.

To achieve this, you will create and configure text labels, sliders, and checkboxes along with drag-and-drop systems. You will be exposed to advanced topics like C# with NGUI, and you will also learn how to build a scrollable viewport. By the end of this book, you will have acquired all the knowledge you need to create UIs with the help of practical steps supported by screenshots.

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 drag-and-drop 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
  • Downloading the example code for this book. 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.

    Table of Contents

    1. NGUI for Unity
      1. Table of Contents
      2. NGUI for Unity
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Getting Started with NGUI
        1. What is NGUI?
          1. UnityGUI versus NGUI
          2. Atlases
          3. Events
          4. Localization
          5. Shaders
        2. Importing NGUI
        3. Creating your UI
          1. UI Wizard
            1. Window
            2. Parameters
          2. Separate UI Layer
        4. Your UI structure
          1. UI Root (2D)
            1. Parameters
          2. Camera
            1. Parameters
          3. Anchor
            1. Parameters
          4. Panel
            1. Parameters
        5. Summary
      9. 2. Creating Widgets
        1. Creating our first widget
          1. Widget Wizard
          2. Selecting an atlas
          3. Creating a widget from a template
          4. Transforming widgets
            1. Moving widgets
            2. Rotating widgets
            3. Scaling widgets
          5. Common widget parameters
        2. Sprites
          1. Sliced sprites
          2. Tiled sprites
          3. Filled sprites
        3. Labels
          1. Parameters
          2. Creating the title bar
        4. Buttons
          1. Parameters
          2. The play and exit buttons
        5. Text input
          1. Parameters
          2. Creating a nickname box
        6. Slider
          1. Parameters
          2. Creating a volume slider
        7. Toggle
          1. Parameters
          2. Creating a sound toggle
        8. Popup list
          1. Parameters
          2. Creating a difficulty selector
        9. Summary
      10. 3. Enhancing your UI
        1. NGUI components
        2. The draggable panel
          1. Parameters
          2. Dragging the MainMenu
        3. The drag-and-drop system
          1. Powers selection
            1. Draggable items container
            2. Draggable items
            3. The drop surface
            4. Prefab instantiated on drop
            5. Handling an invalid drop
            6. Replacing the current item
            7. Removing the current item
        4. Animations with NGUI
          1. Smooth powers apparition
          2. Clipping to hide options
        5. Scrollable text
        6. Localization system
          1. Localization files
          2. Localization component
          3. Language selection box
          4. Localizing a Label
        7. Summary
      11. 4. C# with NGUI
        1. Events methods
          1. Creating a tool tip
            1. The tool tip reference
            2. Showing the tool tip
        2. Tween methods
          1. Main menu apparition
            1. Simple Tween
            2. Smooth Tween
        3. Using keys for navigation
        4. Error notification
        5. Saving the nickname
        6. Sending messages
        7. Forwarding an event
        8. Summary
      12. 5. Building a Scrollable Viewport
        1. Preparing the Game scene
        2. The scrollable viewport
          1. Draggable background
          2. Linking scroll bars
          3. Keyboard scrolling
        3. Creating draggable barriers
          1. The BarrierObject prefab
          2. Dropping a barrier on Viewport
        4. Creating an ActiveBarrier prefab
          1. The ActiveBarrier prefab
          2. Instantiating the ActiveBarrier prefab
          3. Barrier's building process
          4. Forwarding events to viewport
        5. BarrierObject cooldown
          1. Cooldown implementation
          2. BarrierObject smooth apparition
        6. The barrier availability tool tip
        7. Summary
      13. 6. Atlas and Font Customization
        1. The Atlas prefab
        2. Creating a new Atlas
        3. Adding sprites to Atlas
          1. Simple sprites
            1. Adding sprites to Atlas
            2. Available powers icons
            3. Selected powers icons
          2. Sliced sprites
            1. Adding a sprite to Atlas
            2. Configuring a sliced sprite
            3. The Main Menu window
          3. Tiled sprites
        4. Adding a font
          1. Exporting a font using BMFont
          2. Creating a font in Unity
          3. Assigning a new font to Label
        5. Customizing the MainMenu
        6. Summary
      14. 7. Creating a Game with NGUI
        1. Enemy spawning
          1. Creating the enemies container
          2. Creating the Enemy prefab
          3. Creating the enemy spawn controller
          4. Forwarding events to viewport
        2. Handling enemy collisions
          1. Collisions with active barriers
          2. Colliding with the bottom of the screen
            1. Healthbar
            2. The EndOfScreen widget
        3. Creating self-destruct code
          1. The hacking slider
          2. Self-destruct code
          3. Assigning code to an enemy
          4. The hacking process
          5. Handling player input
        4. Summary
      15. Index