{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-asset-optimization-summary/",
  "atlas": "https://www.pystone.net/?node=unity-asset-optimization-summary#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-asset-optimization-summary.md",
  "context": "https://www.pystone.net/notes/unity-asset-optimization-summary.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-asset-optimization-summary",
  "slug": "unity-asset-optimization-summary",
  "title": "U3D资源优化知识点汇总",
  "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": "U3D资源优化知识点汇总",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "15b865e1fd5f031f3c0a3fd390b566a328f7a4b54ca4ab34f5e530917a5811ac",
  "assets": [
    {
      "reference": "assets/0035 - U3D资源优化知识点汇总__2.png",
      "url": "/media/dd4cde88b85e4be989eb.png",
      "mediaType": "image/png",
      "contentHash": "dd4cde88b85e4be989ebd9d7a5e328c7e9c968df63fc4de8d0d89ff1bdb93187",
      "byteLength": 64365,
      "width": 882,
      "height": 378
    },
    {
      "reference": "assets/0035 - U3D资源优化知识点汇总__1.png",
      "url": "/media/a0f3553beddbf5d15e33.png",
      "mediaType": "image/png",
      "contentHash": "a0f3553beddbf5d15e3364f87c7885618b86ea69b96880cc751dd8dea3f1fab2",
      "byteLength": 46795,
      "width": 871,
      "height": 348
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "U3D资源优化知识点汇总",
      "anchor": "u3d资源优化知识点汇总",
      "citation": "https://www.pystone.net/notes/unity-asset-optimization-summary/#u3d%E8%B5%84%E6%BA%90%E4%BC%98%E5%8C%96%E7%9F%A5%E8%AF%86%E7%82%B9%E6%B1%87%E6%80%BB"
    },
    {
      "depth": 2,
      "text": "Audio",
      "anchor": "audio",
      "citation": "https://www.pystone.net/notes/unity-asset-optimization-summary/#audio"
    },
    {
      "depth": 3,
      "text": "ImportSettings",
      "anchor": "importsettings",
      "citation": "https://www.pystone.net/notes/unity-asset-optimization-summary/#importsettings"
    },
    {
      "depth": 3,
      "text": "设置建议",
      "anchor": "设置建议",
      "citation": "https://www.pystone.net/notes/unity-asset-optimization-summary/#%E8%AE%BE%E7%BD%AE%E5%BB%BA%E8%AE%AE"
    },
    {
      "depth": 3,
      "text": "导入后处理脚本",
      "anchor": "导入后处理脚本",
      "citation": "https://www.pystone.net/notes/unity-asset-optimization-summary/#%E5%AF%BC%E5%85%A5%E5%90%8E%E5%A4%84%E7%90%86%E8%84%9A%E6%9C%AC"
    },
    {
      "depth": 2,
      "text": "Cull Transparent Mesh",
      "anchor": "cull-transparent-mesh",
      "citation": "https://www.pystone.net/notes/unity-asset-optimization-summary/#cull-transparent-mesh"
    }
  ],
  "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中的“U3D资源优化知识点汇总”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    }
  ],
  "contentMarkdown": "# U3D资源优化知识点汇总\n\n> 创建时间：2020/9/8 17:58\n\n## Audio\n\n### ImportSettings\n\nForce To Mono：将多声道音频混合为单声道，一般手机使用单声道足够满足需求\nLoad In Background：When this option is enabled, the loading of the clip will happen at a delayed time on a separate thread, without blocking the main thread. 分线程加载， 不阻塞主线程\nAmbisonic：是否环绕声\n\nLoad Type：加载方式\n\n**Decompress On Load** ：在音频 **加载后马上解压缩** 。对 **较小的压缩声音** 使用此选项可以避免动态解压缩的性能开销，不过在加载时解压缩Vorbis编码的声音将使用大约十倍于内存的内存（对于ADPCM编码约为3.5倍），因此请勿对大文件使用此选项。\n**Compressed In Memory** ：将声音压缩在内存中并在 **播放时解压缩** 。 此选项具有轻微的性能开销（特别是对于Ogg / Vorbis压缩文件），因此仅将其 **用于加载时解压缩将使用大量内存的较大的文件** 。 解压缩发生在 **混音器线程** 上，可以在探查器窗口的音频窗格中的”DSP CPU(Digital Signal Processor)”部分进行监视。\n**Streaming** ： **动态解码** 声音。 此方法使用 **最少量的内存来缓冲从磁盘中逐步读取并在运行中解码的压缩数据** 。 解压缩发生在单独的流线程上，可以在Profiler窗口的音频窗格的”Streaming CPU”部分中监视其CPU使用情况。 即使没有加载任何音频数据，Streaming的剪辑也有大约200KB的消耗。\n\nPreload Audio Data：预加载\n\nCompression Format\nPCM：此选项以 **更大的文件** 大小为代价提供 **更高的质量** ，并且最适 **合非常短的声音** 效果。\nADPCM：这种格式对于 **包含大量噪音** 且 **需要大量播放** 的声音非常有用，例如脚步声，撞击声，武器。 **压缩比** 是PCM的 **3.5倍** ，而且 **CPU使用率** 远 **低** 于MP3 / Vorbis格式，这使其成为上述类别声音的首选。\nVorbis/MP3：压缩为较小的文件，但与PCM音频相比 **质量稍低** 。 **压缩量** 可通过”质量”滑块进行 **配置** 。 此格式最适合 **中等长度** 的音效和音乐。\n\nSample Rate Setting： 采样率设置\nPreserve Sample Rate: 保留采样率\nOptimize Sample Rate：此设置根据分析的最高频率内容自动优化采样率。\nOverride Sample Rate：此设置允许手动覆盖采样率，因此可以有效地避免采样内容丢失。\n\n> 要关注:\n>  OriginalSize:磁盘大小\n>  ImportedSize:内存大小\n>  Ratio:ImportedSize占OriginalSize比例\n\n### 设置建议\n\n  1. 建议都勾选ForceToMono：将多声道音频混合为单声道\n\n  2. 在iOS上请使用MP3格式，在Android上使用Vorbis\n\n  3. 场景等长音效使用Streaming + Vorbis/MP3\n\n  4. 技能等短音效使用DecompressOnLoad + ADPCM\n\n  5. 采样率选择手动控制到22050左右\n\n  6. 短音频可选格式aifff或wav，长音频可选格式mp3或ogg\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> Ref:\n>  <https://blog.csdn.net/LeoHiJack/article/details/95228708>\n>  <https://blog.csdn.net/u013244147/article/details/104548393>\n>  <https://zhuanlan.zhihu.com/p/27438828>\n\n## Cull Transparent Mesh\n\nUnity2018.2加入的新功能：Image对应的CanvasRenderer组件上可以勾选Cull Transparent Mesh\n\n> 官方描述：Indicates whether geometry emitted by this renderer can be ignored when the vertex color alpha is close to zero for every vertex of the mesh.\n\n若Image的Color属性的Alpha值接近于0，则该Image是看不见的，如果对其进行渲染，则会造成不必要的渲染性能开销。\n如果在Image对应的CanvasRenderer开启Cull Transparent Mesh，则Unity进行渲染时会对该Image的Color的Alpha值进行检测，若该值接近于0，就忽略该Image，不进行绘制，节约性能。\n\n![Alt text](assets/0035 - U3D资源优化知识点汇总__2.png)\n\n![Alt text](assets/0035 - U3D资源优化知识点汇总__1.png)\n\n如上图，第二张图Image组件的Alpha值为0，由FrameDebugger可见，Unity没有对该Image进行绘制。\n\n更具体的，可见讨论：\nI assume this culling test has a cost, which is why it’s not enabled by default/done automatically.\n\n实现上：\nthis checkbox toggles a shader feature to cull pixels in the fragment shader with very low alpha value.\n\nDocs would seem to indicate this uses the vertex colour alpha at the vertex stage:\n\n<https://docs.unity3d.com/ScriptReference/CanvasRenderer-cullTransparentMesh.html>\n\nBut e.g:\n\n[https://github.com/TwoTailsGames/Un…er/DefaultResourcesExtra/UI/UI-Default.shader](https://github.com/TwoTailsGames/Un...er/DefaultResourcesExtra/UI/UI-Default.shader)\n\n> Ref:\n>  <https://twitter.com/dmitriy_focus/status/1166706421389496321?lang=en>\n>  <https://docs.unity3d.com/ScriptReference/CanvasRenderer-cullTransparentMesh.html>\n>  <https://forum.unity.com/threads/practical-effect-of-cull-transparent-mesh.746711/>\n"
}
