{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-engine-architecture/",
  "atlas": "https://www.pystone.net/?node=unity-engine-architecture#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-engine-architecture.md",
  "context": "https://www.pystone.net/notes/unity-engine-architecture.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-engine-architecture",
  "slug": "unity-engine-architecture",
  "title": "Unity的架构",
  "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": "Unity的架构",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "e767786bb450233de41fcc677fbf8c8f73f382016b5e8b587abe82dd26596b74",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "Unity的架构",
      "anchor": "unity的架构",
      "citation": "https://www.pystone.net/notes/unity-engine-architecture/#unity%E7%9A%84%E6%9E%B6%E6%9E%84"
    },
    {
      "depth": 2,
      "text": "Unity",
      "anchor": "unity",
      "citation": "https://www.pystone.net/notes/unity-engine-architecture/#unity"
    },
    {
      "depth": 2,
      "text": "关于异常",
      "anchor": "关于异常",
      "citation": "https://www.pystone.net/notes/unity-engine-architecture/#%E5%85%B3%E4%BA%8E%E5%BC%82%E5%B8%B8"
    }
  ],
  "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中的“Unity的架构”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    },
    {
      "id": "note:game-dev-graphics-performance",
      "title": "游戏研发、图形与性能",
      "url": "https://www.pystone.net/notes/game-dev-graphics-performance/",
      "atlas": "https://www.pystone.net/?node=game-dev-graphics-performance#knowledge-atlas",
      "label": "游戏研发、图形与性能",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "Unity 的架构提供引擎侧整体入口。",
      "citation": "https://www.pystone.net/notes/game-dev-graphics-performance/#%E4%BB%8E%E6%9E%B6%E6%9E%84%E5%88%B0%E8%BF%90%E8%A1%8C%E6%97%B6"
    }
  ],
  "contentMarkdown": "# Unity的架构\n\n> 创建时间：2020/5/21 20:24\n\n## Unity\n\nUnity当中渲染的部分是用C++执行的\nMono是Unity运行过程中的一部分，负责在特定的时间编译C#脚本，运行C#程序集。\n所以，操作系统之上是基于C++的Unity程序，在Unity当中的一部分是Mono，Mono负责Unity当中与C#相关的部分。\n\n整个Unity程序的运行是基于一帧一帧的刷新来进行的。\n如果在一帧当中，调用了一个耗时比较长的函数，整个程序就会卡在这一帧，直到这个函数调用结束。\n在编辑器模式下，通过MenuItem调用一个函数，就是在一帧里面进行函数调用，这个函数耗时比较长，这一帧就会等待这个函数调用完再刷新。\n\nUnity当中有些程序是支持多线程的，比如烘培操作，烘培的时候，会在右下角开一个进度条，但是Game界面的程序还是会不断地一帧一帧刷新，不会阻塞，就是在多个线程下运行的结果。\n\n在Mono之上是整个C#环境，Unity在运行时，C#环境就一直在内存当中运行的。\n\n## 关于异常\n\n在脚本运行的时候，抛出异常，会一层一层往上抛。\n异常被try catch时，如果catch到，那么try当中的代码就会跳过。也就是说，被try的函数就会在异常出终止，进而从catch语句块之后的代码开始继续运行。\n\n如果自己写的程序不catch这个异常，那么这个异常会最终被Unity catch到，那么，Unity调用的我写的整个函数，就会终止掉。而实际上，整个C#的程序是没有终止的，Unity的C#程序还在内存当中，与我自己catch到异常没有本质的区别。而且，出异常的函数所分配的资源，如果不写代码释放掉，就没有其他好办法来释放了。因为这部分资源是在Unity的C#环境中的，只有重启整个Unity，才能强制释放。\n\n如果某个脚本索引了一个文件流，由于文件流没有被释放而造成文件被锁、无法重新打开，可以对这个脚本进行reimport，Why？\n"
}
