Add a right-click event in Unity

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.