首页 > 代码库 > [cb]右键菜单 GenericMenu
[cb]右键菜单 GenericMenu
自定义窗口中使用右键菜单:
// 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(); } } }}<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。