Version: 2023.1
LanguageEnglish
  • C#

ICreateVerticalToolbar.CreateVerticalToolbarContent

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public Overlays.OverlayToolbar CreateVerticalToolbarContent();

Returns

OverlayToolbar The content of your overlay in vertical toolbar layout form.

Description

Implement this to return your visual element representing the vertical toolbar layout of your overlay.

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.Toolbars;
using UnityEngine;
using UnityEngine.UIElements;

[Overlay(typeof(SceneView), "Custom Toolbar Overlay")]
class CustomOverlay : Overlay, ICreateHorizontalToolbar, ICreateVerticalToolbar
{
    public override VisualElement CreatePanelContent()
    {
        return new Label("I'm the content shown in panel mode!");
    }

    // Setup horizontal layout to only have CustomToolbarItem visual element.
    public OverlayToolbar CreateHorizontalToolbarContent()
    {
        var horizontalOverlayToolbar = new OverlayToolbar();
        horizontalOverlayToolbar.Add(new CustomToolbarItem());

        return horizontalOverlayToolbar;
    }

    // Setup vertical layout to only have OtherToolbarItem visual element.
    public OverlayToolbar CreateVerticalToolbarContent()
    {
        var verticalOverlayToolbar = new OverlayToolbar();
        verticalOverlayToolbar.Add(new OtherToolbarItem());

        return verticalOverlayToolbar;
    }
}

[EditorToolbarElement("SomeOtherToolbarItem", typeof(SceneView))]
class OtherToolbarItem : EditorToolbarToggle
{
    public OtherToolbarItem()
    {
        icon = EditorGUIUtility.FindTexture("CustomTool");
    }
}

[EditorToolbarElement("MyToolbarItem", typeof(SceneView))]
class CustomToolbarItem : OverlayToolbar
{
    public CustomToolbarItem()
    {
        var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("MyIcon");
        Add(new EditorToolbarButton(icon, () => { Debug.Log("Hello!"); }));
        Add(new EditorToolbarButton(icon, () => { Debug.Log("Hello again!"); }));
        SetupChildrenAsButtonStrip();
    }
}