Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Extending Unity with Editor Scripting
Extending Unity with Editor Scripting

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

Arrow left icon
Profile Icon Angelo R Tadres Bustamante
Arrow right icon
€36.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (7 Ratings)
Paperback Sep 2015 268 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Angelo R Tadres Bustamante
Arrow right icon
€36.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (7 Ratings)
Paperback Sep 2015 268 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Extending Unity with Editor Scripting

Chapter 2. Using Gizmos in the Scene View

When you are working on a video game and you need to debug features, it's very helpful to have a visual representation of certain structures you are using in the code. For example, imagine that you have a set of waypoints to model the movement of a Non Playable Character (NPC) in your video game. If it is possible for you to see the waypoints, it will be easier for you to make tweaks and readjust the movement paths.

Thankfully, in Unity there's a class called Gizmos that allow us to add visual aids to the Scene View in an easy way.

Here, you will learn about the Gizmos class and how to use this to create a visual grid that will help level designers position the level piece prefabs with more control in the level.

In this chapter we will cover the following topics:

  • The OnDrawGizmos and OnDrawGizmosSelected methods
  • The DrawGizmo attribute
  • The Gizmos class API

Overview

In Unity, a gizmo is a visual aid rendered in Unity's Scene View to help us in the development process. Several components in Unity use gizmos to tell the developers where in the 3D world these are located.

Take a look at the following screenshot. The two icons, the movie camera and the light bulb, are gizmos that indicate the game object position of the camera and the point light components, respectively.

Overview

You can do the same with a specific game object if you click on the cube icon in their inspector pane:

Overview

Here you have three options to choose:

  • Use a label
  • Use a built-in icon
  • Use a custom icon made with any image located inside your project

You will see the following three results, respectively, in the Scene View:

Overview

Any of these gizmos will be attached to the game object and will persist in the scene and in any prefab containing this game object.

All these examples use the Unity editor to do the required setup, but there is an additional way in which gizmos can be created, allowing...

Creating gizmos through code

We explored how to add simple gizmos through the Unity editor. This section will cover how to properly implement the OnDrawGizmos and OnDrawGizmosSelected methods to achieve a similar but more flexible solution.

Note

All the scripts in this section are examples, and are not meant to be used in the Level Creator tool.

The OnDrawGizmos and OnDrawGizmosSelected methods

To get started, in a new project, create a script called GizmoExample.cs. We will use this as a guinea pig for our first gizmos experiments (don't worry, the script is not going to suffer too much!)

Write the following code in GizmoExample.cs:

using UnityEngine;
public class GizmoExample : MonoBehaviour {
        private void OnDrawGizmos() { 
        }
}

When you implement the OnDrawGizmos method, you can add gizmos that always drawn in the Scene View and also allows the possibility to be selected with a click.

In this case, the method is empty. However, if you come back to Unity and wait for the compiler...

Adding a structure to our levels

Open the Run & Jump project and look for the folder Scripts/Level. Inside this folder, you will find all the related to the video game. The Level class is responsible for making our levels work.

As you may have noticed, in Chapter 1, Getting Started with Editor Scripting, all the level piece prefabs are added to the scene and used by the level without a problem, but we don't have control over the size of the level or any way to guarantee that the level piece prefabs are going to be in the right position. Most important, the Level class is not aware about the level piece prefabs present on the level.

We are going to fix this situation making changes to the Level class, adding an array to save references to the level piece prefabs and define it size based in the total columns and rows supported by that array.

Visually, you are going to see the size of the level with the help of a grid made with gizmos.

As this chapter requires changes on the Level class...

Implementing the gizmo grid

When you open the script Level.cs. You will see the following code:

using UnityEngine;

namespace RunAndJump {
  public partial class Level : MonoBehaviour {

    [SerializeField]
    public int _totalTime = 60;
    [SerializeField]
    private float gravity = -30;
    [SerializeField]
    private AudioClip bgm;
    [SerializeField]
    private Sprite background;

    public int TotalTime {
      get { return _totalTime; }
      set { _totalTime = value; }
    }

    public float Gravity {
      get { return gravity; }
      set { gravity = value; }
    }

    public AudioClip Bgm {
      get { return bgm; }
      set { bgm = value; }
    }

    public Sprite Background {
      get { return background; }
      set { background = value; }
    }
   }
}

This script holds the variables that you saw in the inspector and the properties to access and change these values.

Note

As you may have noticed, making your variables public is not the only way to expose them in the...

Implementing the snap to grid behaviour

To create our first level in Chapter 1, Getting Started with Editor Scripting, we used a hot key to snap the level piece prefabs between them. Here, we will do the same, but instead of using the hot key, the level piece prefabs are going to snap to the grid automatically.

Here, we will assume that the Level game object position and rotation is always (0,0,0) and the scale is (1,1,1). Also, the 2D mode is selected by default.

Implementing the snap to grid behaviour

Later, we will work on how keep this configuration by default. Based on the grid we created, we need to implement a few things to achieve our goal:

  • A way to convert 3D coordinates to grid coordinates and vice versa
  • A way to know when these coordinates are outside the boundaries of the grid

Inside the Level class, add the following methods in the Level.cs script:

public Vector3 WorldToGridCoordinates(Vector3 point) {
  Vector3 gridPoint = new Vector3(
  (int)((point.x - transform.position.x) / GridSize) ,
  (int)((point.y - transform...

Overview


In Unity, a gizmo is a visual aid rendered in Unity's Scene View to help us in the development process. Several components in Unity use gizmos to tell the developers where in the 3D world these are located.

Take a look at the following screenshot. The two icons, the movie camera and the light bulb, are gizmos that indicate the game object position of the camera and the point light components, respectively.

You can do the same with a specific game object if you click on the cube icon in their inspector pane:

Here you have three options to choose:

  • Use a label

  • Use a built-in icon

  • Use a custom icon made with any image located inside your project

You will see the following three results, respectively, in the Scene View:

Any of these gizmos will be attached to the game object and will persist in the scene and in any prefab containing this game object.

All these examples use the Unity editor to do the required setup, but there is an additional way in which gizmos can be created, allowing greater...

Left arrow icon Right arrow icon

Description

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.

Who is this book 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
Estimated delivery fee Deliver to Norway

Standard delivery 10 - 13 business days

€11.95

Premium delivery 3 - 6 business days

€16.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 21, 2015
Length: 268 pages
Edition : 1st
Language : English
ISBN-13 : 9781785281853
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Norway

Standard delivery 10 - 13 business days

€11.95

Premium delivery 3 - 6 business days

€16.95
(Includes tracking information)

Product Details

Publication date : Sep 21, 2015
Length: 268 pages
Edition : 1st
Language : English
ISBN-13 : 9781785281853
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 119.97
Extending Unity with Editor Scripting
€36.99
Unity 5.x Cookbook
€45.99
Unity 5  Game Optimization
€36.99
Total 119.97 Stars icon
Banner background image

Table of Contents

11 Chapters
1. Getting Started with Editor Scripting Chevron down icon Chevron up icon
2. Using Gizmos in the Scene View Chevron down icon Chevron up icon
3. Creating Custom Inspectors Chevron down icon Chevron up icon
4. Creating Editor Windows Chevron down icon Chevron up icon
5. Customizing the Scene View Chevron down icon Chevron up icon
6. Changing the Look and Feel of the Editor with GUI Styles and GUI Skins Chevron down icon Chevron up icon
7. Saving Data in a Persistent Way with Scriptable Objects Chevron down icon Chevron up icon
8. Controlling the Import Pipeline Using AssetPostprocessor Scripts Chevron down icon Chevron up icon
9. Improving the Build Pipeline Chevron down icon Chevron up icon
10. Distributing Your Tools Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(7 Ratings)
5 star 71.4%
4 star 28.6%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Matthew Magginnis Dec 07, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book to dive into the unity editor with. I've personally been working with Unity for over 5 years and have done a lot of editor coding myself and this book teaches you some very valuable ways to create editor tools for any project. The code is pretty clean, but not documented much if at all in some parts. This isn't a huge issue as the the author explains the code in the text to give you an understanding on what it's doing.If you are a beginner with editor scripts & C#, this might be a bit challenging for you as this book quickly gets into some of the more intermediate level scripting techniques that may be difficult to understand. For those that have some experience in both, this will be a pleasure to learn from as it covers some pretty moderate problems when creating tools for the unity editor.Overall this is a great book to learn from as well as use for reference to build editor tools in Unity. The example project that the author has you create through the book is a great way to see how creating editor tools can increase the workflow and development time for all your projects.
Amazon Verified review Amazon
joekelly Dec 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the best Unity books I've purchased. I buy a lot of Packt books, and this one is full of great tips and tricks. If you have been using Unity for a while, and are looking to improve your editor scripting, you definitely can't go wrong here. Well laid out, great information and examples.
Amazon Verified review Amazon
GameDev Nov 21, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book.
Amazon Verified review Amazon
sean321 Nov 11, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I used this to learn how to build a custom level editor for a 2d tile-based game that I'm working on. The information pertaining to custom gizmos and editor windows is invaluable. Great source. Highly recommended.
Amazon Verified review Amazon
Guilherme Nov 27, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I would say It's “the cookbook of customization”. I read many books about Unity to improve my skills but I finally found an interesting book that I can learn different things as how to customize my own tools at the inspector and my scene view, exploring the gizmos to improve my organization, how to set up Git and other cool tricks. The examples are easy to understand and they are done with Unity 5.x with C# with code commented by the author.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela