Unityxyz
006-Adding Buttons to custom Editors
1.1 Introduction
1. In this tutorial we will learn to add buttons to custom editors in Unity.
This will allow us to extend the functionality of monobehaviours by adding additional buttons. We are going to be adding 3 buttons in this tutorial to our Test006 class.
2. Open the 006 folder available on patreon.
1.2 Basic Script
1. Let us open the Test006 script in the unity editor and analyze it in the script as well as in the inspector.
1.2 Adding a custom inspector
1. Let us make a script called as TestEditor006.cs that we will use as custom editor for Test006.
2. To use this as custom editor:
a. Make it inherit from Editor class in UnityEditor namespace.
b. Use a CustomEditor attribute with the type for which this is a custom editor
c. Override the default GUI function to write our own functionality.
base.OnInspectorGUI() tells the unity to draw the default test006 editor.
1.3 Adding buttons
1. To add a button use GUILayout.Button("ButtonName") to add a a button
2. Let us add three buttons in the custom editor
We have added the button in the custom editor but currently they do not perform any function.
1.3 Adding Functionality to buttons
1. Whenever the button is clicked the statement of GUILayout.Button("") is going to return true.
2. Let us add an if statement and any code within that will be executed whenever the button is clicked.