码迷,mamicode.com
首页 > 其他好文 > 详细

[cb]右键菜单 GenericMenu

时间:2014-06-24 08:55:25      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   ext   

自定义窗口中使用右键菜单:
bubuko.com,布布扣 bubuko.com,布布扣 
// 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();
            }
        }
    }
}

[cb]右键菜单 GenericMenu,布布扣,bubuko.com

[cb]右键菜单 GenericMenu

标签:style   class   blog   code   http   ext   

原文地址:http://www.cnblogs.com/zhaoqingqing/p/3799294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!