Mastering Unity Scripting

Book description

Learn advanced C# tips and techniques to make professional-grade games with Unity

In Detail

This book is an easy-to-follow guide that introduces you to advanced tips and techniques to code Unity games in C#. Using practical and hands-on examples across ten comprehensive chapters, you'll learn how C# can be applied creatively to build professional-grade games that sell.

You will be able to create impressive Artificial Intelligence for enemy characters, customize camera rendering for postprocess effects, and improve scene management by understanding component-based architecture. In addition, you will have an in-depth look at the .NET classes used to increase program reliability, see how to process datasets such as CSV files, and understand how to run advanced queries on data. By the end of this book, you'll become a powerful Unity developer, equipped with plenty of tools and techniques to quickly and effectively develop merchantable games.

What You Will Learn

  • Understand core C# concepts, such as class inheritance, interfaces, singletons, and static objects

  • Implement effective Artificial Intelligence for NPCs

  • Work with event-driven programming to optimize your code

  • Develop solid debugging and diagnostic techniques

  • Get to know the Mono Framework and Linq in practical contexts

  • Customize the rendering functionality for postprocess effects

  • Code line of sight, view testing, and other useful algorithms

  • Improve the quality of your code with the help of concepts such as attributes

  • Table of contents

    1. Mastering Unity Scripting
      1. Table of Contents
      2. Mastering Unity Scripting
      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. Unity C# Refresher
        1. Why C#?
        2. Creating script files
        3. Instantiating scripts
        4. Variables
        5. Conditional statements
          1. The if statement
          2. The switch statement
        6. Arrays
        7. Loops
          1. The foreach loop
          2. The for loop
          3. The while loop
          4. Infinite loops
        8. Functions
        9. Events
        10. Classes and object-oriented programming
        11. Classes and inheritance
        12. Classes and polymorphism
        13. C# properties
        14. Commenting
        15. Variable visibility
        16. The ? operator
        17. SendMessage and BroadcastMessage
        18. Summary
      9. 2. Debugging
        1. Compilation errors and the console
        2. Debugging with Debug.Log – custom messages
        3. Overriding the ToString method
        4. Visual debugging
        5. Error logging
        6. Editor debugging
        7. Using the profiler
        8. Debugging with MonoDevelop – getting started
        9. Debugging with MonoDevelop – the Watch window
        10. Debugging with MonoDevelop – continue and stepping
        11. Debugging with MonoDevelop – call stack
        12. Debugging with MonoDevelop – the Immediate window
        13. Debugging with MonoDevelop – conditional breakpoints
        14. Debugging with MonoDevelop – tracepoints
        15. Summary
      10. 3. Singletons, Statics, GameObjects, and the World
        1. The GameObject
        2. Component interactions
          1. GetComponent
          2. Getting multiple components
          3. Components and messages
        3. GameObjects and the world
          1. Finding GameObjects
          2. Comparing objects
          3. Getting the nearest object
          4. Finding any object of a specified type
          5. Clearing a path between GameObjects
          6. Accessing object hierarchies
        4. The world, time, and updates
          1. Rule #1 – frames are precious
          2. Rule #2 – motion must be relative to time
        5. Immortal objects
        6. Understanding singleton objects and statics
        7. Summary
      11. 4. Event-driven Programming
        1. Events
        2. Event management
          1. Starting event management with interfaces
          2. Creating an EventManager
        3. Code folding in MonoDevelop with #region and #endregion
          1. Using EventManager
          2. Alternative with delegates
          3. MonoBehaviour events
          4. Mouse and tap events
          5. Application focus and pausing
        4. Summary
      12. 5. Cameras, Rendering, and Scenes
        1. Camera gizmos
        2. Being seen
          1. Detecting the object visibility
          2. More on the object visibility
          3. Frustum testing – renderers
          4. Frustum testing – points
          5. Frustum testing – occlusion
          6. Camera vision – front and back
        3. Orthographic cameras
        4. Camera rendering and postprocessing
        5. Camera shake
        6. Cameras and animation
          1. Follow cameras
        7. Cameras and curves
          1. Camera paths – iTween
        8. Summary
      13. 6. Working with Mono
        1. Lists and collections
          1. The List class
          2. The Dictionary class
          3. The Stack class
        2. IEnumerable and IEnumerator
          1. Iterating through enemies with IEnumerator
        3. Strings and regular expressions
          1. Null, empty strings, and white space
          2. String comparison
          3. String formatting
          4. String looping
          5. Creating strings
          6. Searching strings
          7. Regular expressions
        4. Infinite arguments
        5. Language Integrated Query
        6. Linq and regular expressions
        7. Working with Text Data Assets
          1. Text Assets – static loading
        8. Text Assets – loading from the local files
          1. Text Assets – loading from the INI files
          2. Text Assets – loading from the CSV files
          3. Text Assets – loading from the Web
        9. Summary
      14. 7. Artificial Intelligence
        1. Artificial Intelligence in games
        2. Starting the project
        3. Baking a navigation mesh
        4. Starting an NPC agent
        5. Finite State Machines in Mecanim
        6. Finite State Machines in C# – getting started
        7. Creating the Idle state
        8. Creating the Patrol state
        9. Creating the Chase state
        10. Creating the Attack state
        11. Creating the Seek-Health (or flee) state
        12. Summary
      15. 8. Customizing the Unity Editor
        1. Batch renaming
        2. C# attributes and reflection
        3. Color blending
        4. Property exposing
        5. Localization
        6. Summary
      16. 9. Working with Textures, Models, and 2D
        1. Skybox
        2. Procedural meshes
        3. Animating UVs – scrolling textures
        4. Texture painting
          1. Step 1 – creating a texture blending shader
          2. Step 2 – creating a texture painting script
          3. Step 3 – setting up texture painting
        5. Summary
      17. 10. Source Control and Other Tips
        1. Git – source control
          1. Step #1 – downloading
          2. Step #2 – building a Unity project
          3. Step #3 – configuring Unity for source control
          4. Step #4 – creating a Git repository
          5. Step #5 – ignoring files
          6. Step #6 – creating the first commit
          7. Step #7 – changing files
          8. Step #8 – getting files from the repo
          9. Step #9 – browsing the repo
        2. Resources folder and external files
        3. AssetBundles and external files
        4. Persistent data and saved games
        5. Summary
      18. Index

    Product information

    • Title: Mastering Unity Scripting
    • Author(s): Alan Thorn
    • Release date: January 2015
    • Publisher(s): Packt Publishing
    • ISBN: 9781784390655