Lab 13 - Extending the editor
Task:
Create an editor window or add property attributes to organize components in your projects.
Score: 1 point
- Each decorated component using property attributes adds 0.2p
- Each custom inspector 0.4p
- Each new editor window 0.6p
Your work should add up to at least 1 point. The system is quite generous, so don't feel limited by the score values. It is not possible to receive more than 1 point though.
Submission:
Create screenshots of your editor modifications. Since you are modifying your projects, then this task can be submitted as a team. Add a text file with all the names!
Using Property Attributes
Property attributes take very little effort to use and offer a lot of benefits. Download the example code and add it into a Unity project.
Example: AttributesExamples.cs
Defining a completely custom inspector view
Unity also supports completely changing the look of a MonoBehaviour or ScriptableObject inspector window. For this you have to:
- Extend a new class from the Editor class for your custom inspector. eg public class MyComponentEditor : Editor
- Mark the class with CustomEditor attribute. [CustomEditor(typeof(MyComponent))]
- Define a OnInspectorGUI method using property drawers and IMGUI.
Video tutorials:
- https://unity3d.com/learn/tutorials/topics/interface-essentials/building-custom-inspector
- https://unity3d.com/learn/tutorials/topics/interface-essentials/property-drawers-custom-inspectors
Adding new editor windows
You can create your own dockable windows inside the editor. This is useful for creating tools and plugins for your projects.
To create a window you must extend the EditorWindow class and define OnGUI method.
Manual: https://docs.unity3d.com/Manual/editor-EditorWindows.html
Scripting reference: https://docs.unity3d.com/ScriptReference/EditorWindow.html