{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-tips-and-tools/",
  "atlas": "https://www.pystone.net/?node=unity-tips-and-tools#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-tips-and-tools.md",
  "context": "https://www.pystone.net/notes/unity-tips-and-tools.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-tips-and-tools",
  "slug": "unity-tips-and-tools",
  "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/7/17 18:41",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "e3700458c7310b00e11e3b3dcf611700912ca1b135e9d23c3f1e86b342a7da17",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "小知识点与小工具",
      "anchor": "小知识点与小工具",
      "citation": "https://www.pystone.net/notes/unity-tips-and-tools/#%E5%B0%8F%E7%9F%A5%E8%AF%86%E7%82%B9%E4%B8%8E%E5%B0%8F%E5%B7%A5%E5%85%B7"
    },
    {
      "depth": 2,
      "text": "Gizmos",
      "anchor": "gizmos",
      "citation": "https://www.pystone.net/notes/unity-tips-and-tools/#gizmos"
    },
    {
      "depth": 2,
      "text": "OnValidate",
      "anchor": "onvalidate",
      "citation": "https://www.pystone.net/notes/unity-tips-and-tools/#onvalidate"
    },
    {
      "depth": 2,
      "text": "动态添加tag",
      "anchor": "动态添加tag",
      "citation": "https://www.pystone.net/notes/unity-tips-and-tools/#%E5%8A%A8%E6%80%81%E6%B7%BB%E5%8A%A0tag"
    },
    {
      "depth": 2,
      "text": "关于enable=false",
      "anchor": "关于enablefalse",
      "citation": "https://www.pystone.net/notes/unity-tips-and-tools/#%E5%85%B3%E4%BA%8Eenablefalse"
    },
    {
      "depth": 2,
      "text": "获取场景点数和面数",
      "anchor": "获取场景点数和面数",
      "citation": "https://www.pystone.net/notes/unity-tips-and-tools/#%E8%8E%B7%E5%8F%96%E5%9C%BA%E6%99%AF%E7%82%B9%E6%95%B0%E5%92%8C%E9%9D%A2%E6%95%B0"
    }
  ],
  "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/7/17 18:41\n\n## Gizmos\n\n**Gizmos** 在编辑模式下Gizmos可以提供可视化的提示。它们只在Scene场景中显示不在Play模式下显示，但是你可以通过工具栏调整它们。\n\n**Gizmos公共类** 允许你绘制图标，线条，和其他的东西。Gizmos在`OnDrawGizmos`方法中执行绘制，它被Unity编辑器自动调用。另一个可选的方法是`OnDrawGizmosSelected`，它只能被可选的对象调用。\n\nDemo: 绘制顶点的位置，利用OnDrawGizmos在每个顶点绘制一个小球。\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## OnValidate\n\n调用时机:\n\n  * 脚本被加载时\n  * Inspector 中的任何值被修改时\n\nCases：\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需要设计人员输入 16 到 4096 之间 2的整数次幂时。\nUnity提供了ClosestPowerOfTwo函数，方便我们取得最接近的值。同时我们使用RangeAttribute 属性来限定一下输入数值的区间，同时能更好的看出来处理后的值跟原始输入值的区别。\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使用场景 -需要“Nitro”车的速度比其他车的速度大至少20mph.\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## 动态添加tag\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## 关于enable=false\n\nWhen a Behaviour is disabled, it will still be on the object and you can even change its properties and call its methods, but the engine will no longer call its Update method.\nWhen a Renderer is disabled, the object turns invisible.\nWhen a Collider is disabled, it won't cause any collision events to happen.\nWhen an UI component is disabled, the player can't interact with it anymore, but it will still be rendered, unless you also deactivate its renderer.\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"
}
