Skip to main content

Posts

Showing posts from 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 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

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

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

Create Unity Custom Editor - Basics (Part 3)

In the previous lesson we covered the core structure of our project and now we are ready to create our own custom inspector. In this lesson we will link our custom inspector script with our monobehaviour script. So lets get started 1) Create a new GameObject inside the hierarchy and attach the TestScript that we created in the previous lesson. 2) Now open the TestScript and write the following code inside it 3) Now go back to Unity and see the inspector window and you will notice two GUI elements that gets populated(Since the variables in our script our marked as public so those variables gets exposed in the inspector window in the form of GUI elements) Now lets link our editor script with our current test script. 4) Open the TestScriptEditor and write the following code inside it Notice a few things we added A new using statement called UnityEditor as this is required to create a custom editor script.(This will allow us to get

Create Unity Custom Editor - Basics (Part 2)

In the previous part we basically created a fundamental structure setup for us to create an Inspector Editor. Now we will start creating some scripts so lets dive in. 1) Create a new  C# script ( TestScript ) inside the Scripts folder we created in part 1( You can name anything related to your project but to keep things simple for this lesson i am taking this name) 2)Create a new C# script ( TestScriptEditor ) inside the Editor folder we created in part 1( We named it accordingly so that we know that it is an editor script which will be used as a custom inspector) 3) Open the Scripts inside Monodevelop or any other Editor that you use for editing the scripts. Now this basically sets up our core structure for creating custom inspectors inside unity. In the next lesson we will cover the editor engine up and running inside of unity. What are you waiting for lets jump into the next lesson

Create Unity Custom Editor - Basics (Part 1)

In this basic lessons we will be going to create our own custom inspectors inside unity. Before we dive in lets get to know what custom inspectors are A custom inspector is basically an overridden inspector window which can help artist and designers to interact with the inspector in a more user friendly manner. It also helps to create a neat looking inspector for your scripts attached to gameobjects. So lets get started with the initial project setup    Steps to follow: 1) Start a fresh project 2) Create a folder name Scripts This will hold all the scripts(typically monobehaviour) which will be attached to a gameobject in the scene. 3) Create a folder name Editor ( Note : it should be the exact same name ) This will hold all the Editor scripts and Unity will automatically detect weather or not the project contains any editor scripts for component scripts. With this done we have the basic fundamental structure setup