Table of Contents

Unity Addressables

Unity Addressables是一个Package:com.unity.addressables@0.3

Addressable底层使用的是AssetBundle


基础概念

When you make an asset “Addressable,” you can use that asset's address to load it from anywhere. Whether that asset resides in the local application or on a content delivery network, the Addressable system locates and returns it.

Addressable可以从本地或者网络加载资源

When you run the Create Addressables Settings command, the Addressables system creates a folder called, AddressableAssetsData, in which it stores settings files and other assets it uses to keep track of your Addressables setup. You should add the files in this folder to your source control system. Note that Addressables can create additional files as you change your Addressables configuration.

Addressable需要创建单独的资源文件夹存储其设置

Addressables packs assets in a group into AssetBundles according to your group settings when you make a content build.

Addressable底层使用的是AssetBundles,默认每个Group会被打成一个Bundle

AssetReference类型用于引用Addressable资源

资源和文件夹都可以被标记为Addressable

Loading Addressable assets uses asynchronous operations.

Addressable的加载操作是异步的

基础使用

先勾选Asset的Addressable选项,设定好名字(名字作为访问索引),管理分类窗口在这里:Window > Asset Management > Addressables

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets; // 引入这个
 
public class WorldManager : MonoBehaviour
{
    void Start()
    {
        // 这是一个异步操作,需要指定一个回调函数
        // 将一个Asset指定为Addressable,指定好Asset的名字,这里传入的就是Asset的名字(字符串)
        Addressables.LoadAssetAsync<GameObject>("ChacheData.prefab").Completed += OnLoadDone;
    }
 
    // 注意回调函数的参数列表
    void OnLoadDone(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle<GameObject> obj)
    {
        Debug.Log("Load Asset Done");
    }
}

使用代码管理分组

主要目的就是,通过代码,自动扫描固定路径下的资源,将其添加到对应的Addressable分组

参考:https://github.com/GZhonghui/UnityTools/blob/master/Wwise/Script/Editor/AD_MarkWwiseAddressable.cs

Build / 构建资源

Build Script / 打包管线:待补充…

零散

  1. Addressable会自己维护一个资源的列表,检查更新、拉取更新这些操作都是可以自动进行的(那么多基本工具功能都不完善,这种迎合手游的功能倒是做得挺快…)

外链资料

  1. 使用 Addressables 来管理资源 https://www.cnblogs.com/liougouren/p/15666166.html
  2. Addressable Asset System入門 https://synamon.hatenablog.com/entry/introduction-to-addressable-asset-system (日语,整个流程讲得比较完整)
  3. Addressable之内容构建 https://zhuanlan.zhihu.com/p/500535555
  4. Addressable | 总体介绍 | Unity3D 教程 https://www.youtube.com/watch?v=5qq2hh4Z7dc (一个视频系列,比较入门,但是讲得很清晰)