When defining AssetBundles there are a few rules to be aware of:
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.
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 特定捆绑包中,但按关卡/场景对其交互式内容进行分组。
无论遵循何种策略,下面这些额外提示都有助于掌控全局: