Version: 2023.1
AssetBundle 工作流程
AssetBundle 依赖项

为 AssetBundle 准备资源

When defining AssetBundles there are a few rules to be aware of:

  • Scenes and Assets can’t be included together in the same AssetBundle. An individual AssetBundle can only contain either Scenes or Assets.
  • A specific Scene or Asset can’t be assigned to more than one AssetBundle
  • AssetBundles can’t contain Script assets
  • Files inside the StreamingAssets folder cannot be put in an AssetBundle
  • The AssetBundle name cannot match the name of the output folder

Beyond those rules you are free to assign any asset to any bundle you desire. However, there are certain strategies to consider when setting up your bundles.

逻辑实体分组

Logical Entity Grouping is a strategy you can use to decide how to organize what goes into each of your project’s AssetBundles. The principle is to base your decisions on the functional portion of the project that each piece of content represents. This includes sections such as User-Interface, characters, environments, and anything else that may appear frequently throughout the lifetime of the application.

示例

  • 捆绑用户界面屏幕的所有纹理和布局数据
  • 捆绑一个/一组角色的所有模型和动画
  • 捆绑在多个关卡之间共享的景物的纹理和模型

Organizing your AssetBundles by Logical Entity Grouping is ideal for downloadable content (DLC), because it allows you to more easily make small changes to your project which don’t require your users to re-download large amounts of additional, unchanged, assets.

为了能够正确实施此策略,最大诀窍在于,负责为各自捆绑包分配资源的开发人员必须熟悉项目使用每个资源的准确时机和场合。

类型分组

Type Grouping is a strategy where you assign assets of similar type, such as audio tracks or language localization files, to a single AssetBundle.

Type grouping can be useful to establish AssetBundles that change rarely, or are potentially identical across multiple target platforms. For example formats like Audio will tend to match between platforms so long as the compression settings are identical. And the format and settings of textures change rarely, so AssetBundles containing only Textures will tend to be compatible with a wider range of player versions than AssetBundles containing scenes, prefabs or script-based objects. Grouping AssetBundles this way may result in fewer AssetBundles changing and requiring distribution when a new build is done. The downside is that more AssetBundles may need to be downloaded and loaded to assemble all dependent objects together at runtime.

并发内容分组

并发内容分组是指将需要同时加载和使用的资源捆绑在一起。可以将这些类型的捆绑包用于基于关卡的游戏(其中每个关卡包含完全独特的角色、纹理、音乐等)。有时可能希望确保其中一个 AssetBundle 中的资源与该捆绑包中的其余资源同时使用。依赖于并发内容分组捆绑包中的单个资源会导致加载时间显著增加。您将被迫下载该单个资源的整个捆绑包。

并发内容分组捆绑包最常见的用例是针对基于场景的捆绑包。在此分配策略中,每个场景捆绑包应包含大部分或全部场景依赖项。

Note: When building an AssetBundle containing a Scene, any Assets referenced by that Scene will also be automatically included in the AssetBundle, unless those Assets are explicitly assigned to a different AssetBundle. This is convenient when doing Concurrent Content Grouping, but you need to keep an eye out for duplicated assets if any referenced assets are also used by other scenes that you are building into separate AssetBundles.

Additional Tips

A project absolutely can and should mix these strategies as your needs require. Using the optimal asset assignment strategy for any given scenario greatly increases efficiency for any project.

例如,一个项目可能决定将不同平台的用户界面 (UI) 元素分组到各自的 Platform-UI 特定捆绑包中,但按关卡/场景对其交互式内容进行分组。

无论遵循何种策略,下面这些额外提示都有助于掌控全局:

  • 将频繁更新的对象与很少更改的对象拆分到不同的 AssetBundle 中
  • 将可能同时加载的对象分到一组。例如模型及其纹理和动画
  • 如果发现多个 AssetBundle 中的多个对象依赖于另一个完全不同的 AssetBundle 中的单个资源,请将依赖项移动到单独的 AssetBundle。如果多个 AssetBundle 引用其他 AssetBundle 中的同一组资源,一种有价值的做法可能是将这些依赖项拉入一个共享 AssetBundle 来减少重复。
  • If two sets of objects are unlikely to ever be loaded at the same time, such as Standard and High Definition assets, be sure they are in different AssetBundles.
  • Consider splitting apart an AssetBundle if less than 50% of that bundle is ever frequently loaded at the same time
  • Consider combining AssetBundles that are small but whose content is frequently loaded simultaneously
  • 如果一组对象只是同一对象的不同版本,请考虑使用 AssetBundle 变体
AssetBundle 工作流程
AssetBundle 依赖项
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961