受启发: Addressable 增量包
Addressable Setting中勾选
制作资源
设置定好资源的热更
下面是检测更新代码和加载资源
1 [SerializeField] 2 private string _entryName = "Assets/Prefab/GameObject.prefab"; 3 4 public Text UpdateLb; 5 // Start is called before the first frame update 6 void Start() 7 { 8 //var _ = StartAsync(); 9 10 StartCoroutine(DoUpdateAddressadble()); 11 } 12 13 IEnumerator DoUpdateAddressadble() 14 { 15 AsyncOperationHandle<IResourceLocator> initHandle = Addressables.InitializeAsync(); 16 yield return initHandle; 17 18 var checkHandle = Addressables.CheckForCatalogUpdates(false); 19 yield return checkHandle; 20 if (checkHandle.Result.Count > 0) 21 { 22 var updateHandle = Addressables.UpdateCatalogs(checkHandle.Result, false); 23 24 yield return updateHandle; 25 26 List<IResourceLocator> locators = updateHandle.Result; 27 foreach (var locator in locators) 28 { 29 List<object> keys = new List<object>(); 30 keys.AddRange(locator.Keys); 31 var sizeHandle = Addressables.GetDownloadSizeAsync(keys); 32 yield return sizeHandle; 33 long totalDownloadSize = sizeHandle.Result; 34 UpdateLb.text = UpdateLb.text + " download size : " + totalDownloadSize; 35 Debug.Log("download size : " + totalDownloadSize); 36 if (totalDownloadSize > 0) 37 { 38 var downloadHandle = Addressables.DownloadDependenciesAsync(keys); 39 while (!downloadHandle.IsDone) 40 { 41 float percentage = downloadHandle.PercentComplete; 42 Debug.Log($"已下载: {percentage}"); 43 UpdateLb.text = UpdateLb.text + $" 已下载: {percentage}"; 44 yield return null; 45 } 46 Debug.Log("下载完毕!"); 47 UpdateLb.text = UpdateLb.text + " 下载完毕" ; 48 Addressables.Release(downloadHandle); 49 } 50 } 51 Addressables.Release(updateHandle); 52 } 53 else 54 { 55 UpdateLb.text = UpdateLb.text + " 没有检测到更新"; 56 } 57 Addressables.Release(checkHandle); 58 59 60 Load(); 61 } 62 void Load() 63 { 64 Addressables.LoadAssetAsync<GameObject>(_entryName).Completed += 65 (op) => 66 { 67 if (op.Status == AsyncOperationStatus.Succeeded) 68 { 69 Debug.Log(op.Result as GameObject); 70 var go = Instantiate(op.Result as GameObject, Vector3.zero, Quaternion.identity, transform); 71 go.transform.localPosition = Vector3.zero; 72 go.transform.localScale = Vector3.one; 73 } 74 }; 75 }
原文是打了Log,我为了方便查看加了一个Text
将Addressable资源build好上传远程
工程打包,这里我打了pc包
运行
======================================================================
好的,这里出了事故
第一次运行之后显示了加载更新4039,刚好和资源大小一致,但是我直接关了进程想看看第二次打开会不会更新,没有更新但是第一次的更新没截图= =
然后悲催的我想重新打个包应该就行了,结果是
我就不淡定了,我包是重新打了,讲道理应该会重新更新才对,
于是我把包又重新删掉,远程的资源也删了,按照上面的流程重新操作一遍
结果.... 只显示更新size 为0
裂开了.....我在重新尝试中.......
想到一个办法,我要坑同事了,哈哈哈..
果然,成功截图..
在我几次尝试后,有这么个疑问:
现象:更新过后,不管我是把包删除重新build,还是把远程资源都删掉,都会显示无更新
但是我把新加的资源和原有的资源(新打的),一起传到远程,他只会更新新加的,但是原有的资源也是可以正常加载出来的
问题:他是把资源更新加载到电脑内存里面吗,我重新打包和删除远程资源无效,是因为更新还在内存中吗?