IMGUI in the Inspector
Using IMGUI to enhance your components works very similarly to the way it does with in-game IMGUI and EditorWindow
IMGUI. However, there are some small changes. First, you write scripts that inherit from Editor
. Second, you use the OnInspectorGUI()
method, not the OnGUI()
method. Third, if you want the Inspector to also contain all its usual data, you need to call the DrawDefaultInspector()
method within your OnInspectorGUI()
method. Lastly, if you want the IMGUI button to appear in line with the various default Inspector elements, you use the GUILayout
base class, rather than the GUI
base class. So, for example, you wouldn’t create a button with the following code:
GUI.Button(new Rect(10, 10, 100, 50), "Text Button");
Instead, you’d create it with this:
GUILayout.Button("Text Button");
Buttons created with GUILayout
do not require a rectangular position and will automatically be positioned within the UI.
I will...