Welcome to this tutorial series where I will explain several important parts about extending the Unity Editor. Extending the editor with your own made tools and inspectors can significantly optimize your (team's) workflow and save lots of valuable production time.
With editor extensions, you can create your editor windows, inspectors, custom editors and define your variable controls. You can completely control how properties and fields are drawn inside the inspector window or add extra functionality.
For this series, I will create a list of data structures inside a Scriptable Object. To make this data list easier to manage we will create a custom editor for it. In this custom editor, we will override the default list view that the default inspector paints for us. I will replace this default list with a neat looking reorderable list that will make it easier to add and remove items, as well as reordering data.
Finally, we will be using the IMGUI system to create a custom property drawer and GUI Control to add some extra functionality to demonstrate what you can do with some simple editor scripting.
For the sake of this tutorial, I will create a list of "shortcuts," which will be saved in a
ScriptableObject data asset. To make it easier to add a "shortcut" I will be creating a Custom Editor to draw a custom inspector for the
ScriptableObject asset. Lastly, I will create a Custom Property Drawer with a custom IMGUI control to change the way we can interact with the inspector. This custom IMGUI control will be able to detect keystrokes and modifier keys and will save them to the corresponding list entry in our
ScriptableObject data asset. This can be useful for a variety of things, such as creating a custom shortcut manager or input system, where you would like to hot bind key events in editor time.
This tutorial will be made out of several parts, each explaining the different aspects of extending the default Unity Editor.
For who is this tutorial
This tutorial is for Unity C# programmers who would like to extend the default functionality of inspector windows. This way, programmers can have a better idea of how to accommodate designers in advanced editor tools. This, in turn, will be great for optimizing workflows and improving time management.
What you will learn
In this tutorial, you will learn how to
Set up a scriptable object to manage dataThis can also be any
MonoBehaviourwith an inspector window. I chose a
ScriptableObjectbecause we will only be managing data.
Create a custom editor for a scriptable objectOverride the default inspector view by writing your own inspector.
Create a reorderable listUse the non-documented built-in reorderable list to make managing large data sets more doable.
Create a custom controlDefine your own GUI controls and functionality by creating your own.
Create a custom property drawer for a custom controlUse a custom property drawer to override a specific property is drawn in the inspector window.
Registering keyboard events.Use the GUI Utility's hot control and keyboard control to detect keyboard changes.
For this tutorial, any version of Unity3D will suffice. All code will be documented and explained. However, it is recommended to at least have a basic/intermediate understanding of C#. Lastly, an IDE such as Visual Studio will be required to type the actual code.
Any version of Unity3D
Basic/Intermediate C# knowledge
IDE (such as Visual Studio/MonoDevelop etc..)
If you are only interested in a specific part, you can skip to the part you'd like here. I do however use the same project and files during the entirety of this series. The project's source can be found in the last part of this series.
- UNITY 3D: Extending The Editor part 1 - Intro
- UNITY 3D: Extending The Editor part 2 - Setting up a data asset and a Custom Editor
- UNITY 3D: Extending The Editor part 3 - Unity's Internal Reorderable List
- UNITY 3D: Extending The Editor part 4 - Custom Property Drawers and Custom IMGUI Controls
Setting up the project
Create a new Unity Project and create the following folders under the main “Assets” directory:
Notice how I made a duplicate directory “Scripts” under “Editor.”? This is important because we will be using editor scripts. These scripts can only be compiled under an “Editor” directory.
When we build this project, all assets within this directory will not be included in the final build as we only need them for use in the editor.
Note: Scripts inside of the "Editor" directory cannot be referenced by scrips outside of the "Editor" directory. This is because the all scripts inside the "Editor" directory are compiled in a different DLL.
This folder structure should now look like this:
In the next part, we will create the
ScriptableObject and a custom editor that will overwrite the default inspector window. Go there now!