EditorWindow Custom Context Menu
這是轉自另一篇文章 EditorWindow Custom Context Menu
Unity中的視窗都可以通過右鍵視窗的tab 或者 點選視窗右上角的一個選單按鈕 來顯示視窗選單項
視窗都有預設的選單項。。可以通過實現 IHasCustomMenu 介面中的 AddItemsToMenu 函式 來新增自定義的選單項
程式碼:
using UnityEditor;
using UnityEngine;
public class CustomMenuEditorWindow : EditorWindow, IHasCustomMenu
{
[MenuItem("Window/Custom Menu Window")]
public static void OpenCustomMenuWindow()
{
EditorWindow window = EditorWindow.GetWindow<CustomMenuEditorWindow>();
}
private GUIContent m_MenuItem1 = new GUIContent("Menu Item 1");
private GUIContent m_MenuItem2 = new GUIContent("Menu Item 2");
private bool m_Item2On = false;
void Awake()
{
titleContent = new GUIContent("Custom Menu");
}
//Implement IHasCustomMenu.AddItemsToMenu
public void AddItemsToMenu(GenericMenu menu)
{
menu.AddItem(m_MenuItem1, false, MenuItem1Selected);
menu.AddItem(m_MenuItem2, m_Item2On, MenuItem2Selected);
//NOTE: do not show the menu after adding items,
// Unity will do that after adding the default
// items: maximize, close tab, add tab >
}
private void MenuItem1Selected()
{
Debug.Log("Menu Item 1 selected");
}
private void MenuItem2Selected()
{
m_Item2On = !m_Item2On;
Debug.Log("Menu Item 2 is " + m_Item2On);
}
}
相關文章
- Android -- Options Menu,Context Menu,Popup MenuAndroidContext
- Clean context menu under MacOSXContextMac
- GUI_PICTURE以及context_menu學習筆記GUIContext筆記
- ABAP:為Table Control建立Context Menu(轉老宋)Context
- 關於使用 Vue 實現 Context-Menu 的思考與總結VueContext
- Custom
- custom activities
- Bootstrap Mega Menuboot
- css dropdown menuCSS
- Ex-menu
- Ultraedit Clipboards (Edit Menu)
- Hide the User MenuIDE
- 【PB】PB中object,control,custom class,custom visual,custom external等概念的區別Object
- graphite custom functionsFunction
- custom event in javascript and jqueryJavaScriptjQuery
- Unknown custom element: <> -
- android的Menu使用Android
- menu.lst詳解
- 實戰Struts-Menu
- Building Custom ComponentsUI
- ContextContext
- Tkinter (10) 選單部件 Menu
- Bookmarks Menu (mac書籤管理)Mac
- Qt Application Menu In Window and MacQTAPPMac
- Use windows batch script to create menuWindowsBAT
- Struts-menu原始碼分析原始碼
- C# Menu中共享MenuItemC#UI
- How to modify multiple items in the SAP menu
- How To Delete Unwanted Boot Menu Itemsdeleteboot
- go 上下文:context.ContextGoContext
- Web Components之Custom ElementsWeb
- Oracle Custom Support Identifier(CSI)OracleIDE
- How to write a custom classloader in javaJava
- 《Lua-in-ConTeXt》02:ConTeXt 計算機Context計算機
- Wise Menu for MacFinder擴充套件程式Mac套件
- 鴻蒙HarmonyOS實戰-ArkUI元件(Menu)鴻蒙UI元件
- 理解ContextContext
- Go ContextGoContext