{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-asset-import-postprocess-animation-optimization/",
  "atlas": "https://www.pystone.net/?node=unity-asset-import-postprocess-animation-optimization#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-asset-import-postprocess-animation-optimization.md",
  "context": "https://www.pystone.net/notes/unity-asset-import-postprocess-animation-optimization.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-asset-import-postprocess-animation-optimization",
  "slug": "unity-asset-import-postprocess-animation-optimization",
  "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": "资源导入后处理&动画文件优化",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "b813919527959da6c3c77cca0835321836b7e86f641312106c472418b9375c02",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "资源导入后处理&动画文件优化",
      "anchor": "资源导入后处理动画文件优化",
      "citation": "https://www.pystone.net/notes/unity-asset-import-postprocess-animation-optimization/#%E8%B5%84%E6%BA%90%E5%AF%BC%E5%85%A5%E5%90%8E%E5%A4%84%E7%90%86%E5%8A%A8%E7%94%BB%E6%96%87%E4%BB%B6%E4%BC%98%E5%8C%96"
    },
    {
      "depth": 2,
      "text": "资源导入的过程",
      "anchor": "资源导入的过程",
      "citation": "https://www.pystone.net/notes/unity-asset-import-postprocess-animation-optimization/#%E8%B5%84%E6%BA%90%E5%AF%BC%E5%85%A5%E7%9A%84%E8%BF%87%E7%A8%8B"
    },
    {
      "depth": 2,
      "text": "对动画资源进行优化",
      "anchor": "对动画资源进行优化",
      "citation": "https://www.pystone.net/notes/unity-asset-import-postprocess-animation-optimization/#%E5%AF%B9%E5%8A%A8%E7%94%BB%E8%B5%84%E6%BA%90%E8%BF%9B%E8%A1%8C%E4%BC%98%E5%8C%96"
    }
  ],
  "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": "游戏性能优化中的“资源导入后处理&动画文件优化”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#%E6%B8%B8%E6%88%8F%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96"
    }
  ],
  "contentMarkdown": "# 资源导入后处理&动画文件优化\n\n> 创建时间：2020/7/16 22:08\n\n**标签：**|  _优化_\n\n## 资源导入的过程\n\n当Unity检测到Assets目录当中的资源文件发生变化时，会根据资源的类型调用相应的Importer对资源进行导入。导入之前的文件，Unity其实是无法操作的。导入之后，会把资源放到Library文件夹中，Unity编辑器中进行操作的、Build导出的、打包成AssetBundle的文件，也就是Library当中的文件。在编辑器外移动文件或者Reimport文件，都会对资源进行重新import。\n\nAssetPostPossessor会在资源导入后对进行处理，每次Import资源之后，都会调用OnPostprocessModel函数。\n\n## 对动画资源进行优化\n\n为了减小动画文件的精度，写了个脚本继承AssetPostPossessor，重写OnPostprocessModel函数，在每次Import动画文件之后，把动画里的scale曲线去掉，curve的浮点数精度降低，可以优化动画文件所占用的资源。\n\n```csharp\nstring s1 = &quot;Hello &quot;;\nstring s2 = s1;\ns1 += &quot;World&quot;;\n\nSystem.Console.WriteLine(s2);\n//Output: Hello\n\n```\n\n该后处理的函数，只影响导入到Library文件夹中的资源，而不会影响Assets文件夹下的资源（如fbx文件），因此，如果资源重新导入（在编辑器外移动位置、Reimport）时，该脚本不在项目当中，那么之前所做的优化就会失效。\n在刚刚把该脚本放入项目中时，一定要Reimport资源，优化才会生效。\n\n而对项目进行Build和AB打包时，使用的资源就是Library中的资源，打成的包是否优化，取决于Library中的资源是否\n"
}
