Join Jesse Freeman for an in-depth discussion in this video A tour of the Inspector, part of Building Custom Tools to Extend the Unity IDE.
- [Voiceover] So in order for us to get started, let's create a new project. We're gonna call this project Extending Unity Editor. Let's set it to 2D mode to keep things simple, and click Create Project. As you can see, my Unity editor is already configured in the style that I like to work in, with my scene above my game view, my hierarchy and my inspector next to each other, and the project and console below that. For this course, we're not gonna do a lot of work in the scene or the game view at all.
We're gonna focus primarily on the inspector window. Let's drag this and simply dock it to the side. This way we get a full view of everything in the inspector and we won't have to do a lot of scrolling. You can set up your windows however you like, but make sure that you have a full view of everything that goes inside the inspector. Before we start building our own tools, let's walk through how the inspector works and a little bit about some of the default settings that the Unity editor will provide us when creating default inspectors.
Let's select the main camera. This is the default game object that exists in our scene. Every game object has a transform, in this case, the main camera also has several other scripts. such as the camera, a gui layer, a flare layer, and an audio listener. Each of these panels inside of the inspector represents a single script that is attached to a game object. Inside of the inspector, you'll see different types of input fields based on the type of the value that's exposed to the inspector.
For the case of our Transform, the Position, Rotation and Scale are all vector threes. On the camera script, a clear flag allows us to have a drop-down, which is probably set to an enum, the Background has a color picker, size is afloat, our Viewport Rect, represents erect, so there's an X Y, width and height, our Target Texture is an object selector. In this case, it's typed to the rendered texture, so this will allow us to pick a rendered texture from either or scene or inside of the asset folder, and the Occlusion Culling and HDR are both check boxes.
As you look at the last three scripts attached to the Camera, you'll see that they have no properties to edit, so you just get the script name and the ability to turn them on and off by the check box next to their name. Let's go ahead and create a sprite that we can use to attach our own scripts to and build custom inspectors later on in the course. We'll go to GameObject, 2D Object, and Sprite. By default, a sprite game object doesn't have sprite set to its renderer. Let's click on the little circle next to the sprite input field, and we'll just choose the background, which is a default sprite included in our project, and set the size to 20 by 20.
Now that we have our sprite, let's go ahead and create some folders in our project to help us keep things organized. We'll start with a Scripts folder and a Scenes folder. Now that we have everything set up, let's save our current scene by hitting Command-S or Control-S if you're on a PC, and put it into the Scenes folder. We'll call this EditorStaging, and save it. Now we have the basic foundation to move on in the project.
- Exposing variables to the Inspector
- Providing attributes to Inspector fields
- Extending the base editor
- Creating custom UI elements
- Modifying the layout of a custom editor
- Building a custom window
- Saving and loading data
- Creating a reorderable list
- Skinning custom inspectors
- Exporting assets as Unity packages