Skip to main content

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 we have a control over the inspector window.

4) Now lets add our public fields back to the inspector by using the EditorGUILayout class.
Write this code



Now go back to unity and you will notice that now both the public fields are now visible in the inspector window(Nothing Exciting Yet)









In the next lesson we will create some more GUI content which will help in improving the design of 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 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 We create a Texture2D object to hold our GUI texture that we just imported. We create a GUIContent object that will help us to add text,icon and tooltip field to our GUI elements. In OnInspectorGUI() method we will load our texture from our resources folder. Next we add the image,text and tooltip to our GUIContent object