Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


MainToolbarDropdown

Describes the content and behaviour of a dropdown element for the main toolbar.
Read time 1 minuteLast updated 8 days ago

Definition

[Icon("UIToolkit/Icons/DropdownField.png")]public sealed class MainToolbarDropdown : MainToolbarElement

Remarks

Return an instance of this class through a static method registered with MainToolbarElementAttribute to add a dropdown element in the main toolbar. The following example demonstrates a dropdown that switches the active scene.
{code Tests/EditModeAndPlayModeTests/EditorToolbar/Assets/Examples/MainToolbarDropdownExample-SceneSelector.cs}
The following example demonstrates a simple selector dropdown.
using UnityEditor;using UnityEditor.Toolbars;using UnityEngine;public class MainToolbarDropdownExample{ const string kElementPath = "Examples/Example Dropdown"; static string selectedItem = "Item 1"; [MainToolbarElement(kElementPath, defaultDockPosition = MainToolbarDockPosition.Middle)] public static MainToolbarElement CreateExampleDropdown() { var content = new MainToolbarContent(selectedItem); return new MainToolbarDropdown(content, ShowDropdownMenu); } static void ShowDropdownMenu(Rect dropDownRect) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Item 1"), false, () => { selectedItem = "Item 1"; MainToolbar.Refresh(kElementPath); }); menu.AddItem(new GUIContent("Item 2"), false, () => { selectedItem = "Item 2"; MainToolbar.Refresh(kElementPath); }); menu.AddItem(new GUIContent("Item 3"), false, () => { selectedItem = "Item 3"; MainToolbar.Refresh(kElementPath); }); menu.DropDown(dropDownRect); }}

Constructors

Constructor

Description

MainToolbarDropdown(UnityEditor.Toolbars.MainToolbarContent,System.Action{UnityEngine.Rect})Specify the content and function of a main toolbar dropdown.

Inheritance