zoukankan      html  css  js  c++  java
  • Unity 添加鼠标右键事件

    把此类放到 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 }
  • 相关阅读:
    PHP 输出true false
    code::blocks 注释快捷键
    GDAL 网址
    wine qq2011安装
    C++ ACM解题
    C++内存分配秘籍—new,malloc,GlobalAlloc详解(Zhuan)
    grub4dos初级教程-入门篇(Z)
    GDAL 编译(转)
    ubuntu双系统安装
    shapfile格式说明(转)
  • 原文地址:https://www.cnblogs.com/GameDeveloper/p/3974223.html
Copyright © 2011-2022 走看看