Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

IOverrideToolbar.PopulateToolbar

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 void PopulateToolbar(Toolbars.OverridableToolbar toolbarType, List<string> elements);

Parameters

Parameter Description
toolbarType The built-in toolbar to override.
elements List of the built-in toolbar's default element IDs.

Description

Overrides the contents of built-in toolbars.

This method is called before populating contents of built-in toolbars that support overriding. Use toolbarType to check which toolbar this method is called for. Change the elements list to remove or reorder the built-in elements, or add the EditorToolbarElementAttribute IDs of custom elements.

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEditor.Toolbars;

[EditorTool("Custom Tool")]
public class CustomTool : EditorTool { }

[CustomEditor(typeof(CustomTool))]
public class CustomToolSettings : Editor, IOverrideToolbar
{
    public void PopulateToolbar(OverridableToolbar toolbarType, List<string> elements)
    {
        switch (toolbarType)
        {
            case OverridableToolbar.ToolSettings:
                // Add a custom button at the end of the Scene view's 'Tool Settings' toolbar
                elements.Add(CustomToolSettingsButton.k_ID);
                break;

            case OverridableToolbar.ViewOptions:
                // Remove '2D' and 'Audio' buttons from the Scene view's 'View Options' toolbar
                elements.Remove("SceneView/2D");
                elements.Remove("SceneView/Audio");
                break;
        }
    }
}

[EditorToolbarElement(k_ID)]
public class CustomToolSettingsButton : EditorToolbarButton
{
    public const string k_ID = "Custom Tool/Settings Button";
    CustomToolSettingsButton() { text = "SB"; }
}