Book Image

Extending Unity with Editor Scripting

By : Angelo Tadres, Angelo R Tadres Bustamante
Book Image

Extending Unity with Editor Scripting

By: Angelo Tadres, Angelo R Tadres Bustamante

Overview of this book

Table of Contents (18 chapters)
Extending Unity with Editor Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Unity is a development platform for creating multiplatform 3D and 2D video games, which is adopted by several studios and indie developers who are looking for something simple, flexible, and powerful. One of its most interesting features is the extensible editor, allowing you to make Unity work for your video game using editor scripting.

If you are looking for a book that will show you how to deal with tasks that are beyond the implementation of Gameplay and are more related to automating and simplifying the creation of content, such as the assets that require a special configuration to make them usable in your levels, and how to enable pipelines to consume and create artifacts used by your video game, then this book is for you.

While improving the workflow of Run & Jump, a 2D platformer videogame, you will learn all the basics of editor scripting, creating an ad hoc tool that works as a level editor, customizing the way Unity imports assets, and getting control over the build creation process. As a bonus, you will also learn how to share the tools created inside your team or sell them at the Asset Store.

By the end of this book, you will be able to extend all the concepts that you learned to build your own tools and customize the Unity editor in future video game projects with confidence.

You can consider this as an entry point to make your development workflow easier.

Enjoy!

What this book covers

Chapter 1, Getting Started with Editor Scripting, introduces you to Unity editor scripting and explains why this is useful to improve the development workflow. In this chapter, the video game, Run & Jump, which is used as a base for this book is presented.

Chapter 2, Using Gizmos in the Scene View, explains how to use gizmos to display debug information in the Scene View. Here, we implement a grid with gizmos to be used as guides in the level editor.

Chapter 3, Creating Custom Inspectors, discusses how to improve the way the Unity components and scripts are presented in the inspector window, creating custom inspectors and using property and decorator drawers. In addition to the this, you will learn how to start adding and using the editor GUI components. Here we go through the process of making a custom inspector for the class responsible for the level logic in Run & Jump.

Chapter 4, Creating Editor Windows, covers how to create an editor window to present information and interact with features in a custom tool. Using some of the editor GUI skills developed in the last chapter, we create a Palette window, which is a quick and visual way to access the prefabs used as building pieces for the video game levels, grouping them by categories.

Chapter 5, Customizing the Scene View, dives into how to add the editor GUI components directly to the Scene View and capture specific events to expand their capabilities. Step by step, we add GUI components to enable and disable different modes we are going to implement on the level editor, like View, Paint, Edit and Erase, changing the way how the user interacts with the tool.

Chapter 6, Changing the Look and Feel of the Editor with GUI Styles and GUI Skins, explains how to change the look and feel of the Unity editor custom tools. Here we finish the level editor investing our time modifying the appearance of it.

Chapter 7, Saving Data in a Persistent Way with Scriptable Objects, describes how to save data in Unity and manipulate it as a reusable asset using scriptable objects. We walk through the process of reallocate certain properties from the class responsible for the level logic to a scriptable object class, making them reusable across levels.

Chapter 8, Controlling the Import Pipeline Using Asset Postprocessor Scripts, demonstrates how to improve and control the importing pipeline using Asset Postprocessor scripts. We work in automating the process of changing the import settings of the assets imported to the project to make them usable by the video game in an easy way.

Chapter 9, Improving the Build Pipeline, discusses how to automate and improve the build creation pipeline modifying the Unity player settings through code and calling scripts outside Unity. Here, we create a basic build pipeline for Run & Jump that publishes the mobile version of it in a distribution platform called AppBlade.

Chapter 10, Distributing Your Tools, concludes this book by showing how to use Unity packages and Git submodules for custom tools distribution, suitable for sharing inside a team, and how to sell content on the Asset Store.

What you need for this book

To follow this book, you will need to download a copy of Unity available at https://unity3d.com/get-unity.

You can use any version of Unity from version 5.0, but we recommend the latest 5.x version, which at the time of writing this is version 5.1.2 (all screenshots have been updated to this version). Don't worry about the kind of license you have, the examples will work with the Personal and Professional Edition.

While working with this book, we will use as base project the video game Run & Jump, available at https://github.com/angelotadres/RunAndJump.

You must have the Run & Jump project in order to test the code in this book.

Who this book is for

This book is for anyone who has 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.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Create a script called LevelInspector.cs inside the folder Editor"

A block of code is set as follows:

public override void OnInspectorGUI() {
    DrawLevelDataGUI();
    DrawLevelSizeGUI();
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public override void OnInspectorGUI() {
    DrawLevelDataGUI();
    DrawLevelSizeGUI();
}

Any command-line input or output is written as follows:

$ git submodule update

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Select the category Misc and then click on the Sign piece"

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.