【Unity实战】值得关注的Addressable新特性

如果您是最近起的Unity项目且有用到Addressable作为内容管理,你可能需要注意一下1.21.15版本的变化:

[1.21.15] - 2023-08-03

  • Fixed an issue where using binary catalogs causes a crash on Android with ARM7.
  • DownloadDepedenciesAsync no longer loads asset bundles into memory
  • Fixed an exception getting thrown in the Addressables Report when drilling into a bundle chain

第二条比较关键,一般对于有热更新需求的项目,平常都是屏蔽掉Catalog的自动拉取,改为脚本手动拉。以我的一个开源工具为例:

IEnumerator DownloadAddressables()
	{
		var downloadDependenciesHandle = Addressables.DownloadDependenciesAsync("default", false);
		while (downloadDependenciesHandle.Status == AsyncOperationStatus.None)
		{
			var progress = downloadDependenciesHandle.GetDownloadStatus().Percent;
			progressText = $"Downloading...{progress}";
			yield return null;
		}
		yield return downloadDependenciesHandle;
		if (downloadDependenciesHandle.Status == AsyncOperationStatus.Succeeded)
		{
			string time = string.Format("{0:yyyyMMddHHMMss}", DateTime.Now);
			PlayerPrefs.SetString("ResVersion", time);
			progressText = "Patching...";
			StartCoroutine(EnterGame());
		}
		else
		{
			progressText = "Failed on downloading updates!";
			Debug.LogError("[HotUpdater] Failed on Addressables.DownloadDependenciesAsync!");
			yield break;
		}
	}

以上是去年7月份时写的代码,我们不难注意到当下载句柄完成时,程序会直接启动一个读取热更新DLL并进入场景的协程(也就是EnterGame)。在1.21.15版本之前,Addressables.DownloadDependenciesAsync会在下载的同时将下载完毕的Group给挂载到内存里。所以你可以完全在下载句柄完成后,不用释放,直接开始读里面的资源。

但是1.21.15版本之后,我们必须卸载下载句柄然后再开始我们的LoadAssetAsync操作,否则的话会提示Provider异常,见下方日志:

至于为什么这么做,目前个人猜测是为了更灵活的管理内存,下载下来不代表要挂载(?)

总之的确是个坑,需要重点关注,尤其是近期开的项目默认安装的Addressable都是比较新的版本,其他倒没什么。

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值