Skip to main content

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










This concludes our lesson on GUIContent.
In the next lesson we will create some GUI Buttons to our custom inspector.  

Comments

Popular posts from this blog

Build Optimization Editor Tool(Android)(WIP)

Note: This version works only with Unity 5.0+ Have you faced problems when dealing with multiple audio files and changing their settings to optimize the build size. Now, with this editor script you can optimize the audio files in the assets folder by selecting only those files which needs modification. In future update you can optimize texture settings for android as well. Current Version -Audio Compression Upcoming Version -Support Texture Compression Download Plugin Here

Create Unity Custom Editor - Basics (Part 4)

In the last lesson we linked our custom editor script with our test script. In this lesson we are going to create some custom GUI elements. So lets get started with that 1) Jump to the Editor Script and comment out the DrawDefaultInspector() so that we can start adding our own custom elements Lets get started with introducing some GUI elements that we can create inside the inspector The most basic one is a label 2) We will be using EditorGUILayout class to show our label inside the inspector. This class has got tons of other types of functions which you can use Goto this link and checkout the other functions available inside the EditorGUILayout class. I would recommend to spend sometime on those functions provided and try to implement all of those so that you can get an idea of how you can use different GUI elements to represent custom inspectors. 3) Now when we go back to unity we will see a label showing inside our inspector. Now this concludes that ...