Version: 1.3
语言 : 中文
后期绑定
Sprite Packer

解析不同的精灵图集情形

Unity 解析精灵和精灵图集之间交互情况的方式取决于各种条件。以下示例详细展现了最常见的情形:

情形 1:基本精灵图集用法

  1. Sprite Atlas A contains Sprite 1.
  2. Sprite Atlas A has Include in Build enabled.
  3. Result: The Project’s published build includes Sprite Atlas A. Sprite 1 renders with the Texture from Sprite Atlas A.

情形 2:禁用“Include in Build”

  1. Sprite Atlas A contains Sprite 1.
  2. Sprite Atlas A has Include in Build disabled.
  3. Result: The Project’s published build does not include Sprite Atlas A, and does not include Sprite 1’s Texture. Sprite 1 appears invisible in the build at run time, because the Texture it refers to is not available and is not loaded.

情形 3:一个精灵位于两个精灵图集中

  1. Sprite Atlas A and Sprite Atlas B both include Sprite 1 in their Objects for Packing lists.
  2. Both Sprite Atlas A and Sprite Atlas B have Include in Build enabled.
  3. Both Sprite Atlases have different Texture output settings in this example.
  4. Result: The Project’s published build includes both Sprite Atlases. Unity randomly chooses which Texture to render Sprite 1 with, in an internal process that is out of your control.

在此情形中,要确保精灵使用所需精灵图集中的纹理进行渲染,请按照以下步骤操作:

  1. Disable ‘Include in Build’ for both Sprite Atlases.
  2. 在运行时初始化精灵时,直接使用 SpriteAtlas.GetSprite 从其中一个图集请求精灵。这样可确保 Unity 始终从正确的精灵图集绘制精灵纹理。
后期绑定
Sprite Packer