精灵图集是在 Unity 中创建的一种资源。它是内置精灵打包解决方案的一部分。
精灵图集可以存储可打包资源的列表。可打包资源可以是 Sprite、TextureImporterType.Sprite 的Texture2D 或文件夹。在打包过程开始前,这些可打包资源将被分组和遍历,以便从中收集所有精灵。这些精灵将在打包过程中使用。在运行时,这些精灵可以通过精灵图集枚举(另请参阅:SpriteAtlas.GetSprites)。
精灵图集还在 Inspector 中为打包的纹理提供了专用的纹理设置。精灵的原始纹理设置不会影响打包的纹理。
默认情况下,精灵图集将被精灵引用,并在运行时可用。这意味着精灵在加载时能够从精灵图集获取打包的纹理。加载精灵时可以不引用任何精灵图集。因为没有纹理,所以以这种方式加载的精灵会渲染为不可见。可以在之后添加对精灵图集的引用。另请参阅:SpriteAtlasManager。
可以通过将其他精灵图集对象指定为主图集来创建精灵图集变体。变体不会重新打包来自可打包列表的新纹理。相反,变体会复制主图集的打包纹理并根据用户定义的比率将其缩小,然后保存缩小后的纹理。
isVariant | 如果此 SpriteAtlas 为变体,则返回 true。 |
spriteCount | 获取打包到此图集中的 Sprite 的总数。 |
tag | 获得此 SpriteAtlas 的标签。 |
CanBindTo | 如果 Sprite 打包到此 SpriteAtlas 中,则返回 true。 |
GetSprite | 克隆此图集中与打包的名称匹配的第一个 Sprite 并将其返回。 |
GetSprites | 克隆此图集中的所有 Sprite 并将其填充到提供的数组内。 |
GetInstanceID | 返回对象的实例 ID。 |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsOfType | Gets a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
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.