把此类放到 Editor下使用就OK
1 using UnityEngine; 2 using System.Collections; 3 using System.Collections.Generic; 4 using UnityEditor; 5 6 /// <summary> 7 /// 添加鼠标右键事件 8 /// </summary> 9 [InitializeOnLoad] 10 [ExecuteInEditMode] 11 public static class AddMouseRight 12 { 13 14 static AddMouseRight() 15 { 16 SceneView.onSceneGUIDelegate = OnSceneFunc; 17 } 18 19 private class Item 20 { 21 public string MenuName { get; set; } 22 public GenericMenu.MenuFunction2 Call { get; set; } 23 } 24 static List<Item> S_MenuList = new List<Item>(); 25 public static void AddMenu(string menuName, GenericMenu.MenuFunction2 call) 26 { 27 Item item = new Item(); 28 item.MenuName = menuName; 29 item.Call = call; 30 S_MenuList.Add(item); 31 } 32 33 static void OnSceneFunc(SceneView sceneView) 34 { 35 if (S_MenuList.Count == 0) 36 { 37 return; 38 } 39 40 if (Event.current.isMouse && Event.current.button == 1) 41 { 42 Vector3 p = Event.current.mousePosition; 43 44 GenericMenu menu = new GenericMenu(); 45 46 foreach(Item i in S_MenuList) 47 { 48 menu.AddItem(new GUIContent(i.MenuName), false, i.Call, p); 49 } 50 menu.ShowAsContext(); 51 52 Event.current.Use(); 53 } 54 } 55 56 public static void Reset() 57 { 58 while(S_MenuList.Count > 0) 59 { 60 S_MenuList.RemoveAt(0); 61 } 62 } 63 64 65 }