{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-editor-extension/",
  "atlas": "https://www.pystone.net/?node=unity-editor-extension#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-editor-extension.md",
  "context": "https://www.pystone.net/notes/unity-editor-extension.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-editor-extension",
  "slug": "unity-editor-extension",
  "title": "编辑器扩展",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "编辑器扩展 创建时间：2020/6/3 15:15",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "ff32b140ec4b1399b1f2318b4279abe8f37ea5fdb394067b784caa5734389586",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "编辑器扩展",
      "anchor": "编辑器扩展",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E7%BC%96%E8%BE%91%E5%99%A8%E6%89%A9%E5%B1%95"
    },
    {
      "depth": 2,
      "text": "编辑器扩展",
      "anchor": "编辑器扩展-1",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E7%BC%96%E8%BE%91%E5%99%A8%E6%89%A9%E5%B1%95-1"
    },
    {
      "depth": 2,
      "text": "菜单项",
      "anchor": "菜单项",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E8%8F%9C%E5%8D%95%E9%A1%B9"
    },
    {
      "depth": 3,
      "text": "MenuItem",
      "anchor": "menuitem",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#menuitem"
    },
    {
      "depth": 4,
      "text": "常用的菜单那位置",
      "anchor": "常用的菜单那位置",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E5%B8%B8%E7%94%A8%E7%9A%84%E8%8F%9C%E5%8D%95%E9%82%A3%E4%BD%8D%E7%BD%AE"
    },
    {
      "depth": 4,
      "text": "验证菜单栏",
      "anchor": "验证菜单栏",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E9%AA%8C%E8%AF%81%E8%8F%9C%E5%8D%95%E6%A0%8F"
    },
    {
      "depth": 4,
      "text": "自定义快捷键",
      "anchor": "自定义快捷键",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BF%AB%E6%8D%B7%E9%94%AE"
    },
    {
      "depth": 4,
      "text": "优先级",
      "anchor": "优先级",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E4%BC%98%E5%85%88%E7%BA%A7"
    },
    {
      "depth": 4,
      "text": "给组件或脚本添加右键方法（Inspector）",
      "anchor": "给组件或脚本添加右键方法inspector",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E7%BB%99%E7%BB%84%E4%BB%B6%E6%88%96%E8%84%9A%E6%9C%AC%E6%B7%BB%E5%8A%A0%E5%8F%B3%E9%94%AE%E6%96%B9%E6%B3%95inspector"
    },
    {
      "depth": 4,
      "text": "其他位置",
      "anchor": "其他位置",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E5%85%B6%E4%BB%96%E4%BD%8D%E7%BD%AE"
    },
    {
      "depth": 3,
      "text": "ContextMenu & ContextMenuItem",
      "anchor": "contextmenu-contextmenuitem",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#contextmenu-contextmenuitem"
    },
    {
      "depth": 3,
      "text": "注册撤销操作",
      "anchor": "注册撤销操作",
      "citation": "https://www.pystone.net/notes/unity-editor-extension/#%E6%B3%A8%E5%86%8C%E6%92%A4%E9%94%80%E6%93%8D%E4%BD%9C"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:game-graphics-and-runtime",
      "title": "游戏图形与运行时",
      "url": "https://www.pystone.net/notes/game-graphics-and-runtime/",
      "atlas": "https://www.pystone.net/?node=game-graphics-and-runtime#knowledge-atlas",
      "label": "游戏图形与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "Unity中的“编辑器扩展”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    }
  ],
  "contentMarkdown": "# 编辑器扩展\n> 创建时间：2020/6/3 15:15\n\n## 编辑器扩展\n\n## 菜单项\n\n### MenuItem\n\n#### 常用的菜单那位置\n\n  1. 整个Unity编辑器顶头的菜单栏；\n\n  2. Inspector挂Component的；\n\n  3. Hierarchy游戏物体节点树的；\n\n  4. Project游戏资源文件的。\n\n#### 验证菜单栏\n\n为某个菜单项写一个bool方法。\n第二个参数表示，是否为验证函数\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        dynamic dyn = 1;\n        object obj = 1;\n        dyn = dyn + 3;\n        //obj = obj + 3; 报错\n\n        // Rest the mouse pointer over dyn and obj to see their\n        // types at compile time.\n        System.Console.WriteLine(dyn.GetType());\n        System.Console.WriteLine(obj.GetType());\n    }\n}\n\n```\n\n#### 自定义快捷键\n\n菜单名称+空格+快捷键\n_g 按下字母g\n修饰符: % Ctrl; # Shift; & Alt\nLEFT、RIGHT、UP、DOWN、F1..F12、HOME、END、PGUP、PGDN\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        dynamic dyn = 1;\n        object obj = 1;\n        dyn = dyn + 3;\n        //obj = obj + 3; 报错\n\n        // Rest the mouse pointer over dyn and obj to see their\n        // types at compile time.\n        System.Console.WriteLine(dyn.GetType());\n        System.Console.WriteLine(obj.GetType());\n    }\n}\n\n```\n\n#### 优先级\n\n默认为1000\n差距为11以上分组\n\n#### 给组件或脚本添加右键方法（Inspector）\n\n传入参数 MenuCommand\ncommand.context : 被右键点击的脚本对象\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        dynamic dyn = 1;\n        object obj = 1;\n        dyn = dyn + 3;\n        //obj = obj + 3; 报错\n\n        // Rest the mouse pointer over dyn and obj to see their\n        // types at compile time.\n        System.Console.WriteLine(dyn.GetType());\n        System.Console.WriteLine(obj.GetType());\n    }\n}\n\n```\n\n#### 其他位置\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        dynamic dyn = 1;\n        object obj = 1;\n        dyn = dyn + 3;\n        //obj = obj + 3; 报错\n\n        // Rest the mouse pointer over dyn and obj to see their\n        // types at compile time.\n        System.Console.WriteLine(dyn.GetType());\n        System.Console.WriteLine(obj.GetType());\n    }\n}\n\n```\n\n### ContextMenu & ContextMenuItem\n\n  * 写在本身Component脚本中，隶属于UnityEngine命名空间，会被打包。\n\n  * 功能和参数与MenuItem完全一致\n\n  * 非静态\n\nContextMenuItem: 给你在右键变量名称时添加菜单\n参数:1.菜单的名称；2.菜单执行的方法，要求脚本中必须有；3.按钮的先后顺序。\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        dynamic dyn = 1;\n        object obj = 1;\n        dyn = dyn + 3;\n        //obj = obj + 3; 报错\n\n        // Rest the mouse pointer over dyn and obj to see their\n        // types at compile time.\n        System.Console.WriteLine(dyn.GetType());\n        System.Console.WriteLine(obj.GetType());\n    }\n}\n\n```\n\n### 注册撤销操作\n\nUndo.RegisterCreatedObjectUndo方法注册撤销操作\n"
}
