Put this class in editor for use.
1 using unityengine; 2 using system. collections; 3 using system. collections. generic; 4 using unityeditor; 5 6 /// <summary> 7 // Add the right-click event 8 /// </Summary> 9 [initializeonload] 10 [executeineditmode] 11 public static class addmouseright12 {13 14 static addmouseright () 15 {16 sceneview. onsceneguidelegate = onscenefunc; 17} 18 19 private class item20 {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 = new item (); 28 item. menuname = menuname; 29 item. call = call; 30 s_menulist.add (item); 31} 32 33 static void onscenefunc (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}
Add a right-click event in Unity