• [cb] Unity Editor 添加右键菜单


    需求

    为Unity的Editor窗口添加右键菜单

    image image 

    实现代码

    // This example shows how to create a context menu inside a custom EditorWindow.
    class MyGenericMenu extends EditorWindow {
        
        @MenuItem("Game/Open Window")
        static function Init () {
            var window = GetWindow (MyGenericMenu);
            window.position = Rect (50, 50, 250, 60);
            window.Show ();
        }
    
        function Callback (obj:Object) {
            Debug.Log ("Selected: " + obj);
        }
    
        function OnGUI() {
            var evt : Event = Event.current;
            var contextRect : Rect = new Rect (10, 10, 100, 100);
            
            if (evt.type == EventType.ContextClick)
            {
                var mousePos : Vector2 = evt.mousePosition;
                if (contextRect.Contains (mousePos))
                {
                    // Now create the menu, add items and show it
                    var menu : GenericMenu = new GenericMenu ();
                    
                    menu.AddItem (new GUIContent ("MenuItem1"), false, Callback, "item 1");
                    menu.AddItem (new GUIContent ("MenuItem2"), false, Callback, "item 2");
                    menu.AddSeparator ("");
                    menu.AddItem (new GUIContent ("SubMenu/MenuItem3"), false, Callback, "item 3");
                    
                    menu.ShowAsContext ();
    
                    evt.Use();
                }
            }
        }
    }
  • 相关阅读:
    DataGridView 控件和 DataGrid 控件之间的区别
    winform 如何创建mdi属性IsMdiContainer=true
    窗体分为左右两部分,要求在左边栏点击按钮时,右边动态加载窗体
    OLEDBConnection 和SQLConnection 有什么区别
    成为一个顶级设计师的八大秘诀
    青春追梦
    四维领导力:明道、取势、优术、树人
    走好青春
    再贺开业
    骑车在暴雨中有感
  • 原文地址:https://www.cnblogs.com/zhaoqingqing/p/3799294.html
Copyright © 2020-2023  润新知