Pages

Tuesday, 14 July 2015

Create Unity Custom Editor - Basics (Part 8) -More GUI elements

In this section we'll create some more interactive gui elements inside our custom editor script
We'll use GUILayout.Button(); to create a button
Notice: This has a bunch of override's that you can look into based on your needs.
For additional reference click here

Now inside our editor script we'll add
GUILayout.Button("Click Me!", GUILayout.Height(40)); 
to create a button with a height of 40 pixels.
So our result will look something like this. Right now the button just sits there and does nothing when we click on it. Let's work on that functionality.

Create Unity Custom Editor - Basics (Part 7) - Inspector Layout

In this lesson we will work on organizing our GUI elements inside the inspector in a more visually appealing manner .

To start with lets wrap our code inside a container by using
EditorGUILayout.BeginHorizontal();
and every time you start with this you have to end the layout by using

EditorGUILayout.EndHorizontal();
Important: Make sure you keep a track of these

Here's the Code
You will notice that all of the GUI elements will align horizontally and some may even go out of the inspector window. However, this is not what we want.

We want our inspector window to look more visually attractive and easy to use. So in order to do that we will nest our container with a BeginVertical and EndVertical layout.
Here's how our code will look like
Notice i have added GUILayout.Space(10) to give some spacing from the margins as well as between the GUI elements.
This concludes the current lesson. In the next section we'll create some more interactive gui elements like buttons,sliders etc.