2D 项目使用精灵和其他图形来创建其场景的视觉效果。这意味着单个项目可能包含许多纹理文件。Unity 通常会为场景中的每个纹理发出一个绘制调用;但是,在具有许多纹理的项目中,多个绘制调用会占用大量资源,并会对项目的性能产生负面影响。
精灵图集 (Sprite Atlas) 是一种将多个纹理合并为一个组合纹理的资源。Unity 可以调用此单个纹理来发出单个绘制调用而不是发出多个绘制调用,能够以较小的性能开销一次性访问压缩的纹理。此外,精灵图集 API 还可以控制如何在项目运行时加载精灵图集。
要创建__精灵图集__,请选择菜单:__Asset > Create > Sprite Atlas__。Unity 在 Asset 文件夹中创建精灵图集,文件扩展名为 *.spriteatlas。
属性 | 描述 |
---|---|
Type | 将精灵图集的 Type 设置为“Master”或“Variant”。默认的 Type 设置为“Master”。将此属性设置为 Variant 时,Unity 会显示额外的属性设置。请参阅有关主精灵图集和变体精灵图集 (Master and Variant Sprite Atlases) 的文档,了解这两种类型的更多相关信息。 |
Include in Build | 选中此复选框可在当前构建中包含精灵图集资源。默认情况下会启用此选项。 |
Allow Rotation | 选中此复选框允许在 Unity 将精灵打包到精灵图集时旋转精灵。这样可以最大限度提高组合后的纹理中的精灵密度,并且默认情况下会启用此选项。如果精灵图集包含画布 UI 元素纹理,请禁用此选项,因为 Unity 在打包期间旋转精灵图集中的纹理时,也会在场景中旋转它们的方向。 |
Tight Packing | 选中此复选框可根据精灵轮廓而非默认矩形轮廓来打包精灵。这样可以最大限度提高组合后的纹理中的精灵密度,并且默认情况下会启用此选项。 |
Padding | 定义精灵图集中各个精灵纹理之间的像素数。这是一个缓冲区,用于防止精灵图集中彼此相邻精灵之间的像素出现重叠。默认值为 4 个像素。 |
Read/Write Enabled | 选中此复选框允许从脚本函数(例如 Texture2D.SetPixels 和其他 Texture2D 函数)访问纹理数据。如果启用此属性,Unity 将创建纹理数据的副本。这会使纹理资源所需的内存量翻倍,并可能对性能产生负面影响。默认情况下会禁用此属性。此属性仅适用于未压缩纹理或 DXT 压缩纹理,因为 Unity 无法读取其他类型的压缩纹理。 |
Generate Mip Maps | 选中此复选框可生成 Mipmap。请参阅有关纹理类型的文档以了解更多信息。 |
sRGB | 选中此复选框可将纹理存储在伽马空间中。请参阅导入纹理文档以了解更多信息。 |
Filter Mode | 选择 Unity 在变换过程中拉伸打包的纹理时如何过滤这些纹理。此设置将覆盖精灵图集中任何已打包的精灵的 Filter Mode设置。请参阅有关纹理类型的文档以了解更多信息。 |
Default (纹理导入器设置面板) | 设置精灵图集的纹理导入器设置。此设置将覆盖精灵图集包含的各个纹理的导入器设置。请参阅有关纹理导入器覆盖的文档以了解更多信息。 |
Objects For Packing | Unity 将此列表中的所有项打包到当前选定的精灵图集中。请参阅有关选择打包对象列表的项的文档以了解更多信息。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.