Version: 2023.2
言語: 日本語

説明

Displays a search field at the top of the menu.

using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

public class ContextMenuWindow : EditorWindow { [MenuItem("My/Context Menu Window")] static void ShowMe() => GetWindow<ContextMenuWindow>();

void CreateGUI() { var contextMenuContainer = new VisualElement(); contextMenuContainer.style.flexGrow = 1; contextMenuContainer.AddManipulator(new ContextualMenuManipulator(e => { e.menu.SetDescriptor(new DropdownMenuDescriptor() { search = DropdownMenuSearch.Auto });

e.menu.AppendAction("Action 1", a => Debug.Log("Action 1 Works"), DropdownMenuAction.AlwaysEnabled); e.menu.AppendAction("Submenu/My Action 2", a => Debug.Log("My Action 2 Works"), DropdownMenuAction.AlwaysEnabled); }));

rootVisualElement.Add(contextMenuContainer); } }