1.当前的控件的Rect

2.当前事件是鼠标按下事件,并且是按下的鼠标右键

3.右键点击位置在Rect内

 

 1 void MyContexMenu(Rect rect)
 2 {
 3     if(Event.current.type == EventType.MouseDown &&
 4         Event.current.button == 1 &&
 5         rect.Contains(Event.current.mousePosition))
 6     {
 7         GenericMenu menu = new GenericMenu();
 8         menu.AddItem(new GUIContent("Menu 1"), false, callback, null);
 9         menu.AddItem(new GUIContent("Menu 2/Sub Menu 1"), false, callback2);
10         menu.ShowAsContext();
11         Event.current.Use();
12     }
13 }

 

public void AddItem(GUIContent content, bool on, MenuFunction func);
public void AddItem(GUIContent content, bool on, MenuFunction2 func, object userData);

参数1:菜单的标题,支持路径

参数2:如果为true,则菜单名称前会打勾

参数3:回调方法

参数4:传递给回调方法的参数


**注意**

当EventType用ContexClick时,不起作用;

有时不起作用可能是点击事件没能传递下去,被上层的组件使用了当前的鼠标事件。

 

相关文章:

  • 2021-11-15
  • 2022-02-12
  • 2021-12-20
  • 2022-01-20
  • 2021-05-23
猜你喜欢
  • 2021-11-28
  • 2021-10-29
  • 2021-10-23
相关资源
相似解决方案