Building a custom inspector

- Now that we have our tile map and a way to create it,let's look into building a custom Editor for the tile map.Inside of our Editor folder, let's create a new script.And we're going to call this TileMapEditor.Then, let's open this up in MonoDevelop.Just like we did before, we going to needto import the UnityEditor.Now again, this script won't be attachedto a game object.Instead, we're going to needto actually extend a class called Editor,which will allow us to create our own custom Inspector.

So let's replace MonoBehaviour with Editor.And let's remove the Start and Update methods.Now, in order for us to link the TileMapEditorto the tile map, we're going to needto create a meta-tag above itthat will associate it with a custom Editor.Let's do open brackets, CustomEditor,and we're going to need to get the typeof the class that we want to use.So in this case, we'll use typeof.And we're going to pass it in to TileMap.

And then we can close the bracket.Now, whenever we select any tile mapin our scene, we're going to get this custom Editorin the Inspector.In order to make sure this works,let's add a quick method just to display a labelinside of the Inspector.Since we're extending the Editor,we're going to need to overridea method called OnInspectorGUI.And then from here, we're going to usea special class to create a label fieldThis class is called the EditorGUILayout.

It has a static method that allows usto create a LabelField.And now we'll pass in a message for it to display.Let's save our script and go back into Unity.If we select the Tile Map,you'll now see in the Inspectorit says Our custom editor.At this point, we now have the basic foundationfor a custom Inspectorand we'll continue to add to this Editoras well as our tile map classto flush this out.

Resume Transcript Auto-Scroll

Author

Updated

7/29/2016

Released

12/7/2015

Learn how to extend the Unity 5 IDE with custom tools like this tile map editor. Investing the time to customize Unity's environment today will make game development much more efficient tomorrow. This simple extension will allow you to easily design large 2D tile maps by simply painting them into your GameObjects. Over the course of the project, Jesse Freeman will show you how to build a tile map class, a custom tile picker, and a tile brush. He'll also show how to customize Unity menus to make your new tools easy to reach.