Loading...

UNITY 3D: Extending The Editor part 1 - Intro and project setup

Intro


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 data

    This can also be any MonoBehaviour with an inspector window. I chose a ScriptableObject because we will only be managing data.
  • Create a custom editor for a scriptable object

    Override the default inspector view by writing your own inspector.
  • Create a reorderable list

    Use the non-documented built-in reorderable list to make managing large data sets more doable.
  • Create a custom control

    Define your own GUI controls and functionality by creating your own.
  • Create a custom property drawer for a custom control

    Use 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.

 

End Result


Before After

 

Requirements


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.

In short:

  • Any version of Unity3D

  • Basic/Intermediate C# knowledge

  • IDE (such as Visual Studio/MonoDevelop etc..)

 

Fast Travel


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.

 

 

Setting up the project


Create a new Unity Project and create the following folders under the main “Assets” directory:

  • Scripts

  • Editor/Scripts

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:

 

Next part


In the next part, we will create the ScriptableObject and a custom editor that will overwrite the default inspector window. Go there now!

Be the first to comment

Post Comment

This website uses cookies to ensure you get the best experience on my website