Editor Windows are a very useful tool. Today we will learn an intermediate Unity programming skill that helps in the distribution of packages and plugins.
Hello everyone, today we will learn an intermediate level Unity programming skill which will be very helpful if you want to create editor tools and make your created packages and plugins easily usable.
What Will We Accomplish in this Blog?
Creating an Inspector GUI
Creating an Editor Window
Serializing classes in Editor Window
Reading values from Editor Window
This might be a long process, so we will divide the workflow into three steps
Step 1: Creating a Data Class
Begin by creating a MonoBehaviour class that keeps our information for creating the Editor Window.
This class stores all the variables we will be using; it's that simple. It stores the variable so they can be displayed in the Editor Window. So, only this class will be attached to GameObject in the Editor.
Step 2: Creating Inspector GUI
Now we will provide options in the Inspector Window in the Editor to choose the class we will display in Editor Window.
This DataEditor class controls variables to be visible in the Inspector window (for now, we display only the enum value). The user will then select the required enum , and the DataEditor class will send a request to the WindowCreator class to create a window and fill in the specific values.
Step 3: Creating Editor Window
Finally, we create the Editor Window with the help of a WindowCreator class that derives from the EditorWindow class and fills data in it.
ℹ️
Make sure to read the code comments as I have explained what each step does there.
Output
Now, let's see the output of our program.
Create an empty gameObject and add DataClass.cs to it.
Change the enum values.
We will see a variable field of the respective animation class.
Provide value in the text field and press the PrintValues button
Voila! We see the result as expected.
This is a simple example to fill values in EditorWIndow and fetch them. This feature has many more use cases so feel free to explore them!