[Game Development] Unity Addressable Packaging Strategy

Preface

For the basics of Addressables, read this article

Addressable full tutorial

Recently, the company is writing a new framework and decided to abandon the old bundle packaging method and use Addressable, so I want to smooth out the new packaging solution and solve all the questions.

text

The ultimate goal of packaging is to build a bunch of Bundle files, and what factors will affect the package results? To sum up, there are 3 key factors and 1 non-key factor.

Key factor 1: AssetGroups Customize AssetGroup

Key factor 2: BundleMode

Key factor 3: Custom Label

You can understand how to use these three items in one picture

Modify the Bundle Mode of the Group

It used to be Pack Together, but now it is changed to Pack Together By Label to perform incremental packaging.

It can be found that the old bundle file is still there, but three new bundle files have been added. It is obvious from the name that all is the old bundle, which means there is no Label, and the new bundle creates three bundles based on the label. They are labelless mode and two texture_1 texture_2.


[Question] If the resources in different Groups are set to the same Label, will they be put into the same bundle? The test found that they will not be put into the same bundle.


Non-critical factor 1: A setting of Group > Content Update Restriction

Why are the first three critical factors and this one a non-critical factor?

Answer: This option needs to be determined before packaging for the first time. Incremental packaging cannot be changed in the future. If it is changed, an error will occur (unless it is a complete package). Therefore, the content of the package is constantly changing, but this option cannot be changed. To hot update resources, select dynamic resources or uncheck Prevent Updates and use the default options. If the resource is rarely updated, it can be set to static.

The old version of Addressable has two options

Cannot Change Post Release: Static resources

Can Change Post Release: Dynamic resources

new version

Prevent Updates Whether to prevent updates

Please note! ! !

无论是新版本还是老版本,首次打包一定要确定好这个Group的Content Update Restriction选项并且在以后的版本中不允许更改,除非以后要再次完整的打包才可以更改。下面做个测试,看看Content Update Restriction到底有什么用

默认情况下是不勾选Prevent Updates或Can Change Post Release:动态资源

如果勾选了Prevent Updates或者是使用了Cannot Change Post Release:静态资源,资源发生改变并且执行增量打包时,你会看到Addressables Groups界面各种黄灯警告

Unity会提示你需要把改变的资源移动到一个新的Group中,并且你可以自己定义该Group的名字

当你点击ApplyChanges后,被警告的资源就会跑到这个新的Group中,如下图所示。

官方建议我们把项目中不常改动的资源设置为静态资源


打包粒度控制

接下来要考虑的问题是,Bundle的粒度要如何控制,假设我把所有资源放到一个Group中,那一个微小的改动就要下载整个bundle包,这肯定是不科学的。

那可否让每一个资源独立成一个Bundle,虽然这么做可行,但是考虑到效率也是不建议这么做的。颗粒度过小要考虑到IO发烫的问题。

有了上面两个疑问,那解决方案就比较清晰了,方案是:有的资源独立一个bundle,有的资源按文件夹打成一个bundle。被多个资源引用的公共资源,按文件夹打成一个bundle或每个资源独立一个bundle。

疑问:哪些资源需要按文件夹打包,哪些资源要独立一个bundle?

先来看看所有要打包的东西有哪些:

Atlas、Sprite、Lua脚本、Shader、Setting(Unity序列化Asset)、txt配表或者bytes配表数据、视频、音频、字体、预设(3D角色、特效、2DSpine、Live2D)

打包资源就是上述文件,而怎么区分用哪种策略呢

类型

是否依赖其他文件

以文件/文件夹打包

纯被动依赖

引用文件

Atlas

文件

Sprite

Guess you like

Origin blog.csdn.net/liuyongjie1992/article/details/129427673