

To add a button to your editor, all you need to do is to use GUILayout.Button() as an argument for an if statement. This should give you the following: GUI Buttonīuttons are one of the most useful things that you can add to your editor. _active = EditorGUILayout.Toggle("Toggle", _active) GUILayout.Label("Is the object(s) available in the scene?", EditorStyles.boldLabel) Just create boolean variable and use Toggle() function: This should give you the following: GUI ToggleĬreating a toggle for your custom editor is also very simple. _color = EditorGUILayout.ColorField("Color", _color) GUILayout.Label("Pick a color for your object(s)", EditorStyles.boldLabel) GUILayout.Label("Name your object(s)", EditorStyles.boldLabel) The only difference is instead of making a string (or int, float, etc) variable, you use Color. The process of adding color picker into your editor is pretty much the same with creating a text field. GUI ColorĪlso one of the most commonly used elements. Otherwise, you will get a null-value error. Also, make sure that whenever you create the variable, it’s value is initialized. _name = EditorGUILayout.TextField("Name", _name) įor text fields, it’s important to dedicate and create its own variable to assign the value of the text field.
#010 EDITOR CUSTOM VARIABLE HOW TO#
Feel free it experiment with me and learn how to display user interfaces") GUILayout.Label("This is a label with no styles at all. GUILayout.Label("Welcome to your very own editor", EditorStyles.largeLabel)
#010 EDITOR CUSTOM VARIABLE UPDATE#
Let’s head back to our script and update its code to the following: You probably remember this but back in the day, OnGUI() is used to draw buttons, labels, and other user interfaces in the game but ever since the new UI system is added to Unity, OnGUI() becomes something that you only use for the editor. To do that, we’ll have to use the built-in function OnGUI().

Now that we have our custom editor window working, it’s time for us to add content inside this window. Save the script and you should be able to create your own editor window. Otherwise, create and show a new one and return its instance of it.

Basically, what GetWindow() will do is it will check if the CustomUnityEditor type already exists in Unity. In the update above, we just added the GetWindow() to render a custom editor window. GetWindow ("Custom Unity Editor Window") Public class CustomUnityEditor : EditorWindow
