Book Image

Extending Unity with Editor Scripting

Book Image

Extending Unity with Editor Scripting

Overview of this book

Table of Contents (18 chapters)
Extending Unity with Editor Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the GUI for the Palette


In this section, we will add our custom GUI and functionalities to the Palette window.

Creating tabs

We want to use the category names as labels for a set of tabs in the Palette window. When we select one of these tabs, only the level piece prefabs of the selected category will be displayed.

We will create a method called GetListFromEnum. This will help us to easily list enums for further use. Let's add this method inside the EditorUtils class:

public static List<T> GetListFromEnum<T> () {
    List<T> enumList = new List<T> ();
    System.Array enums = System.Enum.GetValues (typeof(T));
    foreach (T e in enums) { 
        enumList.Add (e);
    }
    return enumList;
}

The method receives an enum type as a generic type and returns a list with all the enum values in it.

Now, to create the GUI for the tabs, we need to make a few updates in the PaletteWindow.cs script, as follows:

using UnityEngine;
using UnityEditor;
using System.Collections...