CoffeRight
CoffeRight

Reputation: 143

How to create custom enum like this on right top section in Unity Editor

I have a question about how to create a custom enum that looks like one of the ones used in the top right section of the Unity editor (visible in the picture)?

I want to add one custom enum to the right site of ,,Layers'' enum button presented on the screen.

Specifically, I'm looking for a reference to the documentation or the name of an element that should be overwritten/used when building your own editor element :)

Pictore from Unity editor

Upvotes: 0

Views: 769

Answers (1)

SeLeCtRa
SeLeCtRa

Reputation: 627

You can use ready to use library Unity Toolbar Extender for that. You can easily extend unity's built-in toolbar from script.

This example code is shown in action in the gif below. Just hook up your GUI method to ToolbarExtender.LeftToolbarGUI or ToolbarExtender.RightToolbarGUI to draw left and right from the play buttons.

[InitializeOnLoad]
public class SceneSwitchLeftButton
{
    static SceneSwitchLeftButton()
    {
        ToolbarExtender.LeftToolbarGUI.Add(OnToolbarGUI);
    }

    static void OnToolbarGUI()
    {
        GUILayout.FlexibleSpace();

        if(GUILayout.Button(new GUIContent("1", "Start Scene 1"), ToolbarStyles.commandButtonStyle))
        {
            SceneHelper.StartScene("Assets/ToolbarExtender/Example/Scenes/Scene1.unity");
        }

        if(GUILayout.Button(new GUIContent("2", "Start Scene 2"), ToolbarStyles.commandButtonStyle))
        {
            SceneHelper.StartScene("Assets/ToolbarExtender/Example/Scenes/Scene2.unity");
        }
    }
}

enter image description here

Upvotes: 1

Related Questions