Unity_Addressable_Addressables and SpriteAtlases(打包和图集)
Some SpriteAtlas options can change how Unity loads Sprites. This is important to consider if you want to use the Use Asset Database Play Mode Script.
译:一些SpriteAtlas选项可以更改Unity加载Sprites的方式。如果要使用Use Asset Database Play Mode Script,则需要考虑这一点
The following examples demonstrate how Addressables handles SpriteAtlases differently than other Assets:
译:以下示例演示了Addressables如何与SpriteAtlases处理方式不同于其他资产:
Addressable Sprites
Example 1:
You have three Addressable textures in three separate groups, where each texture builds to around 500KB. Since they exist in separate groups, Unity builds them into three separate AssetBundles. Each AssetBundle uses around 500KB and only contains the sprite texture and associated metadata, with no dependencies.
译:您有三个独立组中的三个Addressable纹理,每个纹理构建约为500KB。由于它们存在于不同的组中,Unity将它们构建为三个独立的AssetBundle。每个AssetBundle使用约500KB,仅包含精灵纹理和相关元数据,没有任何依赖项。
Example 2:
The three textures in Example 1 are put into a non-Addressable SpriteAtlas. In this case, Unity still generates three AssetBundles, but they are not the same size .One of the AssetBundles contains the atlas texture and uses about 1500KB. The other two AssetBundles only contain Sprite metadata and list the atlas AssetBundle as a dependency.
Although you can't control which AssetBundle contains the texture, the process is deterministic, so the same AssetBundle will contain the texture through different rebuilds. This is the main difference from the standard duplication of dependencies. The sprites are dependent on the SpriteAtlas texture to load, and yet that texture is not built into all three AssetBundles, but is instead built only into one.
译:示例1中的三个纹理放入非Addressable SpriteAtlas中。在这种情况下,Unity仍会生成三个AssetBundle,但它们大小不同。其中一个AssetBundle包含Atlas纹理,使用约1500KB。另外两个AssetBundle仅包含精灵元数据,并将Atlas AssetBundle列为依赖项。
虽然您无法控制哪个AssetBundle包含纹理,但该过程具有确定性,因此同一AssetBundle将通过不同的重建包含纹理。这是与标准依赖项复制的主要区别。精灵依赖于SpriteAtlas纹理进行加载,但该纹理并未构建到所有三个AssetBundle中,而是仅构建到一个AssetBundle中。
Example 3:
This time, the SpriteAtlas from Example 2 is marked as Addressable in its own AssetBundle. Unity now creates four AssetBundles. If you use Unity version 2020.x or newer, this builds as you would expect. The three AssetBundles with the sprites are each only a few KB and have a dependency on the fourth AssetBundle, which contains the SpriteAtlas and is about 1500KB. If you are using 2019.4 or older, the texture itself may end up elsewhere. The three Sprite AssetBundles still depend on the SpriteAtlas AssetBundle. However, the SpriteAtlas AssetBundle may only contain metadata, and the texture may be in one of the other Sprite AssetBundles.
译:现在,Example 2中的SpriteAtlas被标记为Addressable,并放在自己的AssetBundle中。Unity现在创建了四个AssetBundle。如果您使用的是Unity版本2020.x或更高版本,则构建与您所期望的相同。具有sprites的三个AssetBundle每个仅为几KB,并具有对第四个AssetBundle的依赖关系,该AssetBundle包含SpriteAtlas并且大小约为1500KB。如果您使用的是2019.4或更早版本,则纹理本身可能会在其他地方。三个Sprite AssetBundles仍依赖于SpriteAtlas AssetBundle。但是,SpriteAtlas AssetBundle可能仅包含元数据,而纹理可能在其他Sprite AssetBundles之一中。
Addressable Prefabs With Sprite dependencies
Example 1:
You have three Addressable sprite prefabs - each prefab has a dependency on its own sprite (about 500KB). Building the three prefabs separately results in three AssetBundles of about 500KB each.
译:您有三个Addressable sprite prefabs-每个prefab均依赖于自己的sprite(约为500KB)。分别构建三个prefab将生成约500KB的三个AssetBundle。
Example 2:
The three textures from the previous example are added to a SpriteAtlas, and that atlas is not marked as Addressable. In this scenario, the SpriteAtlas texture is duplicated. All three AssetBundles are approximately 1500KB. This is expected based on the general rules about duplication of dependencies, but goes against the behavior seen in "Addressable Sprite Example 2".前面示例中的三个纹理添加到SpriteAtlas中,并且该Atlas未标记为Addressable。在这种情况下,SpriteAtlas纹理会被复制。三个AssetBundle大小均约为1500KB。根据依赖项复制的一般规则预期会出现此情况,但与“Addressable Sprite Example 2”中看到的行为相反。
译:
Example 3:
The SpriteAtlas from the previous example is now also marked as Addressable. Conforming to the rules of explicit inclusion, the SpriteAtlas texture is included only in the AssetBundle containing the SpriteAtlas. The AssetBundles with prefabs reference this fourth AssetBundle as a dependency. This will lead to three AssetBundles of about 500KB and one of approximately 1500KB.
译:前面示例中的SpriteAtlas现在也被标记为Addressable。符合显式包含规则,SpriteAtlas纹理仅包含在包含SpriteAtlas的AssetBundle中。具有prefabs的AssetBundle将此第四个AssetBundle作为依赖项引用。这将导致三个约为500KB的AssetBundle和一个约为1500KB的AssetBundle。