{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/",
  "atlas": "https://www.pystone.net/?node=unity-atlas-sprite-atlas#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-atlas-sprite-atlas.md",
  "context": "https://www.pystone.net/notes/unity-atlas-sprite-atlas.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-atlas-sprite-atlas",
  "slug": "unity-atlas-sprite-atlas",
  "title": "Atlas【图集】",
  "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": "Atlas【图集】",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "01d71fb345b626bf650f5e826de960e459af4deb75f3efba47c22df7921b97da",
  "assets": [
    {
      "reference": "assets/1618326776601.png",
      "url": "/media/6f91bc98574d8a52fe33.png",
      "mediaType": "image/png",
      "contentHash": "6f91bc98574d8a52fe33f5ff87c0a886ef3fc68da0a65b0317365dceaa88c72f",
      "byteLength": 3522,
      "width": 261,
      "height": 69
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "Atlas【图集】",
      "anchor": "atlas图集",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#atlas%E5%9B%BE%E9%9B%86"
    },
    {
      "depth": 2,
      "text": "Sprite的本质",
      "anchor": "sprite的本质",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#sprite%E7%9A%84%E6%9C%AC%E8%B4%A8"
    },
    {
      "depth": 2,
      "text": "图集（Atlas）的本质",
      "anchor": "图集atlas的本质",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#%E5%9B%BE%E9%9B%86atlas%E7%9A%84%E6%9C%AC%E8%B4%A8"
    },
    {
      "depth": 3,
      "text": "图集的作用",
      "anchor": "图集的作用",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#%E5%9B%BE%E9%9B%86%E7%9A%84%E4%BD%9C%E7%94%A8"
    },
    {
      "depth": 2,
      "text": "Unity中的图集功能",
      "anchor": "unity中的图集功能",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#unity%E4%B8%AD%E7%9A%84%E5%9B%BE%E9%9B%86%E5%8A%9F%E8%83%BD"
    },
    {
      "depth": 3,
      "text": "Late Binding technology",
      "anchor": "late-binding-technology",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#late-binding-technology"
    },
    {
      "depth": 4,
      "text": "Preparing Sprite Atlases for distribution",
      "anchor": "preparing-sprite-atlases-for-distribution",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#preparing-sprite-atlases-for-distribution"
    },
    {
      "depth": 4,
      "text": "Late Binding",
      "anchor": "late-binding",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#late-binding"
    },
    {
      "depth": 2,
      "text": "Texture Packer",
      "anchor": "texture-packer",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#texture-packer"
    },
    {
      "depth": 3,
      "text": "Texture Packer的图集 vs. Unity Atlas的区别",
      "anchor": "texture-packer的图集-vs-unity-atlas的区别",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#texture-packer%E7%9A%84%E5%9B%BE%E9%9B%86-vs-unity-atlas%E7%9A%84%E5%8C%BA%E5%88%AB"
    },
    {
      "depth": 3,
      "text": "命令行使用",
      "anchor": "命令行使用",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%BD%BF%E7%94%A8"
    },
    {
      "depth": 3,
      "text": "更多用法",
      "anchor": "更多用法",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#%E6%9B%B4%E5%A4%9A%E7%94%A8%E6%B3%95"
    },
    {
      "depth": 2,
      "text": "相关链接",
      "anchor": "相关链接",
      "citation": "https://www.pystone.net/notes/unity-atlas-sprite-atlas/#%E7%9B%B8%E5%85%B3%E9%93%BE%E6%8E%A5"
    }
  ],
  "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中的“Atlas【图集】”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    }
  ],
  "contentMarkdown": "# Atlas【图集】\n\n> 创建时间：2021/4/13 23:09\n\n  * Atlas【图集】\n    * Sprite的本质\n    * 图集（Atlas）的本质\n      * 图集的作用\n    * Unity中的图集功能\n      * Late Binding technology\n        * Preparing Sprite Atlases for distribution\n        * Late Binding\n    * Texture Packer\n      * Texture Packer的图集 vs. Unity Atlas的区别\n      * 命令行使用\n      * 更多用法\n    * 相关链接\n\n## Sprite的本质\n\n原本的数据是图片，图片导入后，Sprite类型的设置以及Sprite的分割都是在ImportSettings当中设置的。而ImportSettings的信息就存储在.meta文件当中。因此，Sprite的本质就是meta文件当中存储的图集名称、ID及在原图片上的偏移量等信息。\n\n## 图集（Atlas）的本质\n\n将Sprite集合设置为图集后，图集资源存储的就是Sprite索引的集合，在打包时，会将图集合并为Texture2D类型的资源放入包中，然后再放入各个Sprite的名称、ID以及在图集上的偏移量。\n\n### 图集的作用\n\n  * 节省内存 - OpenGL载入纹理图片时，所用内存会自动扩张到2的N次方。如果图片大小为64*65，那么就会按照64*128载入。\n\n  * 减小包体 - 合成的大图会比之前所有的散图所占用的物理存储更小\n\n  * 提升载入速度 - 将很多小图拼接成一张大图，载入内存时一次载入，提高了载入速度。\n\n  * DrawCall合批\n\n## Unity中的图集功能\n\n> 只有Sprite模式的图片才可以打包成图集\n\n旧版：\nSprite Mode 设置为 Muitiple 设置Packing Tag\nWindow->Sprite Packer –>点击 Pack 即可\n\n新版：\nProject Setting -> Editor -> Sprite Packer -> Mode = Always Enabled\n新建 Sprite Atlas\n选择打包图集的文件夹或者依次添加单独图片，点击Pack Preview后自动打包成一个图集\n\n代码获取图集并动态选择Sprite：\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### Late Binding technology\n\nInclude in Build - Unity includes the Sprite Atlases with the Project’s build and automatically loads them at the build’s run time.\n\n![Alt text](assets/1618326776601.png)\n\n#### Preparing Sprite Atlases for distribution\n\nDisable ‘Include in Build’ - Unity does not include the disabled Sprite Atlas in the Project’s published build, and does not automatically load it at run time.\n\nMethods：\n\n  1. Place the Sprite Atlases into the build’s Resources folder.\n\n  2. Distribute them as downloadable AssetBundles.\n\n#### Late Binding\n\nthe build does not automatically load a prepared Sprite Atlas at run time.\n\nSpriteAtlasManager.atlasRequested - Trigger when any **Sprite was bound to SpriteAtlas** but **couldn’t locate the atlas asset during runtime**.\n\n  * 如果图集勾选Include in Build，在打包时，图集本身就会被自动打入AB包当中，加载Prefab时，就会把图集加载进内存，也就不会触发atlasRequested\n\n  * 不勾选Include in Build，在打包时，图集不会自动进入prefab所在的AB包，也不会自动加载出来，触发atlasRequested事件后，在相应的回调函数当中加载图集，即可实现延迟绑定，图集加载出来之后即可显示。\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```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## Texture Packer\n\n### Texture Packer的图集 vs. Unity Atlas的区别\n\nUnity打图集时会将设置的一个sprite集合打入一张Texture2D当中，不会生成png、jpg等编码的图片格式，而在打包成AssetBundle后会生成一个Texture2D类型的资源。将合并后的Texture2D类型的资源以及各个图集的名称、ID、偏移量存储到包中。\n\n* * *\n\nTexture Packer的基本使用：\n\nTexture Packer会将图集合并成图片，生成一张合并后的PNG，并生成 `.tpsheet`文件（图集表），存储各个Sprite的名称以及偏移量。\n\n在Unity中安装TexturePacker Importer插件后，将合并后的图集以及`.tpsheet`表格导入Unity后，插件会自动读取该信息，并根据该信息处理合并后的图片的ImportSettings，拆分Sprite，在Unity中还原TexturePacker中的设置。\n\n### 命令行使用\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其他相关参数：\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### 更多用法\n\n见官网：<https://www.codeandweb.com/texturepacker/unity>\n\n## 相关链接\n\n图集的详细介绍：<https://www.cnblogs.com/msxh/p/14194756.html>\n<http://blog.justbilt.com/2013/12/12/use_tp_on_command_line/>\n<https://zhuanlan.zhihu.com/p/89332754>\n"
}
