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

Detect If Your Device Is Connected To Wifi using Python

Have you ever wanted to see the list of devices connected to your local home network? Linux provides a cool solution to list all the devices connected to your network using arp scanning. You need to follow these simple steps:(These are for Linux) 1) Make sure you have arp-scan package installed (if not use  sudo apt-get install arp-scan  command in terminal to install the package) 2) In order to verify type  sudo arp-scan --interface=wlan0 --localnet   in terminal. You will probably see the list of devices connected to your local network using wifi. This sets our base and now we can move on to write our python script to detect particular devices and see  there status if its connected to wifi or not. NOTE: We need to know the mac address of the devices we want to track. Now Let's create a new python script and name it anything you like and paste this code  I named mine detectDeviceOnWifi.py Now run your script using  sudo python detectDeviceOnWifi.py  in

Create Unity Custom Editor - Basics (Part 5)

In this lesson we will create some layout for our custom inspector to have a better control on the layout of our inspector window We will start with EdiorGUILayout Class In our code write After clicking save when we go back to unity we will see all our GUI elements in a single horizontal line. This is not what we want. So to fix this we add our GUI elements inside BeginVertical and EndVertical Layout. Now our Code will look like this Clicking on save we will notice our layout gets change back to vertical and all the GUI elements get stacked on top of each other One more feature that these layout allow us is adjusting the space between GUI elements In our code we will add In the horizontal layout we add GUILayout.Space(10)  to add 10px space on both ends of the horizontal layout Now we can go further and add space between our GUI elements by adding  GUILayout.Space(10) between our GUI elements In our code we will add Since we are in a Vertical Co