Pages

Tuesday, 6 January 2015

Create Unity Custom Editor - Basics (Part 6)

In this lesson we will add some GUI content to our custom inspector which will help us to add either

  • Image Icon
  • Text
  • Tooltip
to our GUI elements.

So lets start by adding a sample icon to our GUI elements.

I'll be using this image as a sample







You can use any image that you would like to based on your needs.

We need to import this image inside Unity.

Create a folder named Resources inside the Editor Folder and then
import the image inside this folder like this










Now select the image and set the texture property to GUI as we will be using this image for our GUI elements.









Now in our Code add the following lines


  1. We create a Texture2D object to hold our GUI texture that we just imported.
  2. We create a GUIContent object that will help us to add text,icon and tooltip field to our GUI elements.
  3. In OnInspectorGUI() method we will load our texture from our resources folder.
  4. Next we add the image,text and tooltip to our GUIContent object we created and assign them to the GUI elements.

Click save and now go back to unity and check the inspector window to see the changes

Our final output looks like this










Look into the unity documentation for more information on EditorGUILayout
This concludes our lesson on GUIContent.
In the next lesson we will work on creating inspector layouts.