You are previewing Extending Unity with Editor Scripting.
O'Reilly logo
Extending Unity with Editor Scripting

Book Description

Put Unity to use for your video games by creating your own custom tools with editor scripting

About This Book

  • Acquire a good understanding of extending Unity’s editor capabilities for a platformer game by using Gizmos, custom inspectors, editor windows, scriptable objects, and more

  • Learn to configure and get control over your asset import pipeline using asset preprocessors

  • A step-by-step, comprehensible guide to creating and customizing a build pipeline that fits the necessities of your video game development team

  • Who This Book Is For

    This book is for anyone who has a basic knowledge of Unity programming using C# and wants to learn how to extend and create custom tools using Unity editor scripting to improve the development workflow and make video game development easier.

    What You Will Learn

  • Use Gizmos to create visual aids for debugging

  • Extend the editor capabilities using custom inspectors, property and decorator drawers, editor windows, and handles

  • Save your video game data in a persistent way using scriptable objects

  • Improve the look and feel of your custom tools using GUIStyles and GUISkins

  • Configure and control the asset import pipeline

  • Improve the build creation pipeline

  • Distribute the custom tools in your team or publish them in the Asset Store

  • In Detail

    One of Unity's most powerful features is the extensible editor it has. With editor scripting, it is possible to extend or create functionalities to make video game development easier. For a Unity developer, this is an important topic to know and understand because adapting Unity editor scripting to video games saves a great deal of time and resources.

    This book is designed to cover all the basic concepts of Unity editor scripting using a functional platformer video game that requires workflow improvement.

    You will commence with the basics of editor scripting, exploring its implementation with the help of an example project, a level editor, before moving on to the usage of visual cues for debugging with Gizmos in the scene view. Next, you will learn how to create custom inspectors and editor windows and implement custom GUI. Furthermore, you will discover how to change the look and feel of the editor using editor GUIStyles and editor GUISkins. You will then explore the usage of editor scripting in order to improve the development pipeline of a video game in Unity by designing ad hoc editor tools, customizing the way the editor imports assets, and getting control over the build creation process. Step by step, you will use and learn all the key concepts while creating and developing a pipeline for a simple platform video game. As a bonus, the final chapter will help you to understand how to share content in the Asset Store that shows the creation of custom tools as a possible new business. By the end of the book, you will easily be able to extend all the concepts to other projects.

    Style and approach

    This book uses a step-by-step approach that will help you finish with a level editor tool, a custom configuration for the asset import pipeline, and a build pipeline totally adjusted to the video 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 code file.

    Table of Contents

    1. Extending Unity with Editor Scripting
      1. Table of Contents
      2. Extending Unity with Editor Scripting
      3. Credits
      4. Foreword
      5. About the Author
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. 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. Errata
          3. Piracy
          4. Questions
      9. 1. Getting Started with Editor Scripting
        1. Overview
        2. Editor scripting basics
          1. What is an editor script?
          2. The Editor folder
        3. Introducing Run & Jump
          1. Playing the video game
          2. Creating a new level
        4. The Level Creator tool
          1. Defining the chapter goals
          2. Preparing the environment
          3. Performing automation
        5. Summary
      10. 2. Using Gizmos in the Scene View
        1. Overview
          1. Defining the chapter goals
        2. Creating gizmos through code
          1. The OnDrawGizmos and OnDrawGizmosSelected methods
          2. Adding gizmos using the DrawGizmo attribute
          3. The Gizmos class
            1. DrawCube
            2. DrawWireCube
            3. DrawSphere
            4. DrawWireSphere
            5. DrawRay
            6. DrawLine
            7. DrawIcon
            8. DrawGUITexture
            9. DrawFrustrum
        3. Adding a structure to our levels
        4. Implementing the gizmo grid
        5. Implementing the snap to grid behaviour
        6. Summary
      11. 3. Creating Custom Inspectors
        1. Overview
          1. Defining the chapter goals
        2. Upgrading the Level class
        3. Understanding how an inspector works
        4. Creating a custom inspector
          1. Using the CustomEditor attribute
          2. Playing with the inspector message methods and target variable
          3. Adding the GUI elements
          4. Implementing the resize feature
          5. Using buttons to trigger actions
        5. Working with layouts
          1. Creating complex layouts
        6. Improving the inspector without custom inspectors
          1. What is a Property Drawer?
          2. Built-in Property Drawers
            1. Range
            2. Multiline
            3. TextArea
            4. ContextMenu
            5. ContextMenuItem
          3. Built-in Decorator Drawers
            1. Header
            2. Space
            3. Tooltip
          4. Creating you own Property Drawers
        7. Using drawers inside a custom inspector
          1. Using SerializedObject and SerializedProperty
        8. Summary
      12. 4. Creating Editor Windows
        1. Overview
          1. Defining the chapter goals
        2. Creating the base for an editor window
          1. Using the EditorWindow class
          2. Playing with the EditorWindow message methods
          3. Using Hotkeys to trigger menu items
        3. Implementing the Palette
          1. Creating a category system
          2. Finding assets using the AssetDatabase class
        4. Implementing the GUI for the Palette
          1. Creating tabs
          2. Creating a scrollable area
        5. Integrating the Palette with the Level Creator tool
          1. Creating an event
          2. Subscribing to an event
        6. Summary
      13. 5. Customizing the Scene View
        1. Overview
          1. Defining the chapter goals
        2. Defining the Editor modes
        3. Customizing the Scene View
          1. Using the OnSeceneGUI message method
          2. Playing with the Scene View tools
          3. Controlling the focus over our game objects
        4. Detecting Scene View events
          1. Getting the mouse position
          2. Capturing mouse events
        5. Implementing the Level Creator modes
          1. The View mode
          2. The Paint mode
          3. The Erase mode
          4. The Edit mode
        6. Using the Handles class
        7. Adding the final details to Level Creator
          1. Using hiding flags
        8. Summary
      14. 6. Changing the Look and Feel of the Editor with GUI Styles and GUI Skins
        1. Overview
          1. Defining the chapter goals
        2. Changing the look and feel of the Level Creator tool
          1. Using GUIStyles in our GUI components
          2. Working with the GUIStyleState instances
        3. Changing the look and feel using a simpler approach
          1. Creating a GUISkin asset
          2. Integrating and using a GUISkin
        4. Summary
      15. 7. Saving Data in a Persistent Way with Scriptable Objects
        1. Overview
          1. Defining the chapter goals
        2. Preparing the environment
          1. Updatable gravity in levels
          2. Playing with gravity
        3. Implementing a Scriptable Object
          1. Creating the data class
          2. Generating an asset to contain the data class
        4. Integrating the Scriptable Object with the level
          1. Updating the Level and the LevelInspector class
          2. Tweaking the level settings in the play mode
        5. Summary
      16. 8. Controlling the Import Pipeline Using AssetPostprocessor Scripts
        1. Overview
          1. Defining the chapter goals
          2. Using the AssetPostprocessor class
        2. Improving the import pipeline
          1. Overwriting the background and level piece assets settings
        3. Using a DLL file for the AssetPostprocessors
          1. Creating and setting up a DLL project
          2. Integrating the DLL file to the main project
        4. Summary
      17. 9. Improving the Build Pipeline
        1. Overview
          1. Defining the chapter goals
          2. Preparing the environment
        2. Automating the BuildPipeline class
          1. Adjusting the player settings
          2. Using the BuildPipeline class
          3. Creating an editor window and learning about EditorPrefs to persist data
        3. Adding version control to your project
        4. Interacting with external scripts
          1. Displaying the build information in the video game
          2. Using the bash script in our pipeline
        5. Distributing your video game using AppBlade
          1. Creating an AppBlade account
          2. Uploading the build
        6. Summary
      18. 10. Distributing Your Tools
        1. Overview
          1. Defining the chapter goals
        2. Preparing the environment
        3. Sharing code using a Unity Package
          1. Creating a package
          2. Importing a package
        4. Sharing code using Git submodules
          1. Creating a submodule
          2. Using a submodule
        5. Publishing in the Asset Store
          1. Installing the Asset Store Tools
          2. Becoming a publisher
          3. Uploading the package
          4. Using the Mass Labeler
          5. Uploading and submitting the project
        6. Summary
      19. Index