Unity_Addressable_如何打包AB包
You have a few options when choosing how the assets in a group are packed into AssetBundles:译:当你选择一个组中的资产如何打包到资产包时,你有几个选项:
You can pack all Addressables assigned to a group together in a single bundle. This corresponds to the "Pack Together" bundle mode. For more information see Advanced Group Settings.译:您可以将分配给一个组的所有Addressables打包在一个捆绑包中。这对应于“Pack Together”捆绑模式。有关详细信息,请参阅高级组设置
You can pack each Addressable assigned to a group separately in its own bundle. This corresponds to the "Pack Separately" bundle mode. For more information see Advanced Group Settings.译:您可以将分配给组的每个Addressable分别打包到自己的bundle中。这对应于“单独打包”捆绑模式。有关详细信息,请参阅高级组设置。
You can pack all Addressables sharing the same set of labels into their own bundles. This corresponds to the "Pack Together By Label" bundle mode. For more information see Advanced Group Settings.译:您可以将共享同一组标签的所有Addressables打包到它们自己的捆绑包中。这对应于“按标签打包”捆绑模式。有关详细信息,请参阅高级组设置。
Scene assets are always packed separately from other Addressable assets in the group. Thus a group containing a mix of Scene and non-Scene assets always produces at least two bundles when built, one for scenes and one for everything else.译:场景资产总是与组中的其他可寻址资产分开打包。因此,一个包含场景和非场景资产的组合的组在构建时总是产生至少两个捆绑包,一个用于场景,一个用于其他所有东西
Assets in folders that are marked as Addressable and compound assets like Sprite Sheets are treated specially when you choose to pack each Addressable separately:译:当你选择将每个Addressable分别打包时,标记为Addressable的文件夹中的资产和像Sprite Sheets这样的复合资产会被特别对待
All the assets in a folder that is marked as Addressable are packed together in the same folder (except for assets in the folder that are individually marked as Addressable themselves).译:标记为Addressable文件夹中的所有资产都打包在同一个文件夹中(文件夹中的资产本身单独标记为Addressable除外)。
Sprites in an Addressable Sprite Atlas are included in the same bundle.译:可寻址精灵地图中的精灵包含在同一个包中
See Content Packing & Loading settings for more information.
译:有关更多信息,请参阅内容包装和装载设置。
NOTE
Keeping many assets in the same group can increase the chance of version control conflicts when many people work on the same project.
译:当许多人在同一个项目上工作时,将许多资产放在同一个组中会增加版本控制冲突的机会。
The choice whether to pack your content into a few large bundles or into many smaller bundles, can have consequences at either extreme:
译:选择是将你的内容打包成几个大的捆绑包还是许多小的捆绑包,可能会产生极端的后果:
Dangers of too many bundles:
译:太多捆绑的危险:
Each bundle has memory overhead. This is tied to a number of factors, outlined on that page, but the short version is that this overhead can be significant. If you anticipate 100's or even 1000's of bundles loaded in memory at once, this could mean a noticeable amount of memory eaten up.译:每个bundle都有内存开销。这与许多因素有关,在那一页中概述了,但简短的版本是,这种开销可能很重要。如果您预计一次将有100个甚至1000个bundle加载到内存中,这可能意味着占用了大量内存
There are concurrency limits for downloading bundles. If you have 1000's of bundles you need all at once, they cannot not all be downloaded at the same time. Some number will be downloaded, and as they finish, more will trigger. In practice this is a fairly minor concern, so minor that you'll often be gated by the total size of your download, rather than how many bundles it's broken into.译:下载包有并发性限制。如果你同时需要1000多个捆绑包,你就不能同时下载它们。一些数字将被下载,当他们完成时,更多的数字将被触发。在实践中,这是一个相当小的问题,以至于你经常会被你下载的总大小所限制,而不是它被分成了多少个包。
Bundle information can bloat the catalog. To be able to download or load catalogs, we store string-based information about your bundles. 1000's of bundles worth of data can greatly increase the size of the catalog.译:捆绑信息可能会导致目录膨胀。为了能够下载或加载目录,我们会存储关于您的捆绑包的基于字符串的信息。数千个捆绑包的数据可能会极大地增加目录的大小。
Greater likelihood of duplicated assets. Say two materials are marked as Addressable and each depend on the same texture. If they are in the same bundle, then the texture is pulled in once, and referenced by both. If they are in separate bundles, and the texture is not itself Addressable, then it will be duplicated. You then either need to mark the texture as Addressable, accept the duplication, or put the materials in the same bundle. See Asset and AssetBundle dependencies for more information.译:更容易出现重复的资源。比如说两个材质球都被标记为可定址,且都依赖于同一张贴图。如果它们在同一个捆绑包中,那么这张贴图只会被加载一次,并且被两个材质球引用。但如果它们在不同的捆绑包中,而且这张贴图本身没有被标记为可定址,那么它就会被复制。这时,你需要将这张贴图标记为可定址,接受重复,或将这两个材质球放在同一个捆绑包中。有关更多信息,请参见有关资产和资产捆绑包依赖项的文档
Dangers of too few bundles:
译:包裹太少的危险:
The UnityWebRequest (which we use to download) does not resume failed downloads. So if a large bundle is downloading and your user loses connection, the download is started over once they regain connection.译:UnityWebRequest(我们用来下载的)不会恢复失败的下载。因此,如果你的用户正在下载一个大的捆绑包,而你的用户失去了连接,一旦他们重新连接,下载就会重新开始
Items can be loaded individually from bundles, but cannot be unloaded individually. For example, if you have 10 materials in a bundle, load all 10, then tell Addressables to release 9 of them, all 10 will likely be in memory. See Memory management for more information.译:项目可以从捆绑包中单独加载,但不能单独卸载。例如,如果你在一个bundle中有10个材料,加载全部10个,然后告诉Addressables释放其中的9个,这10个都可能在内存中。有关更多信息,请参阅内存管理。
Scale implications as your project grows larger
As your project grows larger, keep an eye on the following aspects of your assets and bundles:
译:随着项目规模的扩大,需要注意资产和捆绑包的以下几个方面:
Total bundle size: Historically Unity has not supported files larger than 4GB. This has been fixed in some recent editor versions, but there can still be issues. It is recommended to keep the content of a given bundle under this limit for best compatibility across all platforms.译:总捆绑包大小:历史上Unity不支持大于4GB的文件。最近的一些编辑器版本已经解决了这个问题,但仍可能存在问题。建议将给定捆绑包的内容保持在此限制以下,以实现最佳的跨所有平台的兼容性。
Bundle layout at scale: The memory and performance trade-offs between the number of AssetBundles produced by your content build and the size of those bundles can change as your project grows larger.译:捆绑包布局的规模:随着项目规模的扩大,由内容构建生成的AssetBundle数量与这些捆绑包的大小之间的内存和性能权衡可能会发生变化。
Bundle dependencies: When an Addressable asset is loaded, all of its bundle dependencies are also loaded. Be aware of any references between assets when creating Addressable groups. See Asset and AssetBundle dependencies for more information.译:捆绑包依赖关系:当加载一个可定址的资源时,它的所有捆绑包依赖项也会被加载。在创建可定址组时,请注意资产之间的任何引用。有关更多信息,请参见有关资产和资产捆绑包依赖项的文档。
Sub assets affecting UI performance: There is no hard limit here, but if you have many assets, and those assets have many subassets, it may be best to turn off sub-asset display. This option only affects how the data is displayed in the Groups window, and does not affect what you can and cannot load at runtime. The option is available in the groups window under Tools > Show Sprite and Subobject Addresses. Disabling this will make the UI more responsive.译:子资产影响UI性能:这里没有硬性限制,但如果您有许多资产,这些资产有许多子资产,最好关闭子资产显示。此选项仅影响在组窗口中显示数据的方式,并不影响您可以在运行时加载什么和不能加载什么。该选项在组窗口下的“Tools > Show Sprite and Subobject Addresses.”中可用。禁用此选项可以使UI更加响应。
Group hierarchy display: Another UI-only option to help with scale is Group Hierarchy with Dashes. This is available within the inspector of the top level settings. With this enabled, groups that contain dashes '-' in their names will display as if the dashes represented folder hierarchy. This does not affect the actual group name, or the way things are built. For example, two groups called "x-y-z" and "x-y-w" would display as if inside a folder called "x", there was a folder called "y". Inside that folder were two groups, called "x-y-z" and "x-y-w". This will not really affect UI responsiveness, but simply makes it easier to browse a large collection of groups.译:组层次结构显示:另一个用于帮助处理规模的仅限UI选项是使用破折号的组层次结构。这在顶级设置的检查器中可用。启用此选项后,名称中包含破折号“-”的组将显示为如果这些破折号代表文件夹层次结构。这不会影响实际的组名称或构建方式。例如,名为“x-y-z”和“x-y-w”的两个组将显示为如果在名为“x”的文件夹中,有一个名为“y”的文件夹。在该文件夹中有两个名为“x-y-z”和“x-y-w”的组。这不会真正影响UI的响应性,只是使浏览大量组更加容易。