IEnumerator UpdateCatalogs() { AsyncOperationHandle<List<IResourceLocator>> updateHandle = Addressables.UpdateCatalogs(); yield return updateHandle; Addressables.Release(updateHandle); }
IEnumerator UpdateCatalog() { var start = DateTime.Now; updateHandle = Addressables.UpdateCatalogs(needUpdateCatalogs, false); yield return(updateHandle); Debug.Log(string.Format("UpdateCatalogFinish use {0}ms", (DateTime.Now - start).Milliseconds)); foreach (var item in updateHandle.Result) { Debug.Log("catalog result " + item.LocatorId); foreach (var key in item.Keys) { Debug.Log("catalog key " + key); } needUpdateKeys.AddRange(item.Keys); } if (needUpdateKeys.Count > 0) { StartDownload(); } else { Skip(); } Addressables.Release(updateHandle); }
IEnumerator checkUpdate() { //初始化Addressable var init = Addressables.InitializeAsync(); yield return(init); //开始连接服务器检查更新 AsyncOperationHandle <List <string> > checkHandle = Addressables.CheckForCatalogUpdates(false); //检查结束,验证结果 yield return(checkHandle); if (checkHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = checkHandle.Result; if (catalogs != null && catalogs.Count > 0) { Debug.Log("download start"); var updateHandle = Addressables.UpdateCatalogs(catalogs, false); yield return(updateHandle); Debug.Log("download finish"); } } Addressables.Release(checkHandle); }
public IEnumerator CheckAssets() { var handle = Addressables.CheckForCatalogUpdates(false); //BootScreen.Instance.SetLabel("正在检查更新..."); //BootScreen.Instance.SetProgress(0); while (!handle.IsDone) { yield return(null); } if (handle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = handle.Result; Debug.Log("Catalog Update Count:" + catalogs.Count.ToString()); if (catalogs != null && catalogs.Count > 0) { foreach (var catalog in catalogs) { Debug.Log(catalog); } var updateHandle = Addressables.UpdateCatalogs(catalogs, true); while (!updateHandle.IsDone) { //BootScreen.Instance.SetProgress(updateHandle.PercentComplete); yield return(null); } List <object> updateKeys = new List <object>(); var locators = updateHandle.Result; foreach (var locator in locators) { updateKeys.AddRange(locator.Keys); } yield return(UpdateAssets(updateKeys.ToArray())); Addressables.Release(updateHandle); } else { yield return(UpdateComplete()); } } else { yield return(UpdateComplete()); } Addressables.Release(handle); yield return(null); }
/// <summary> /// 检查更新目录 /// </summary> /// <returns></returns> IEnumerator CheckCatalogUpdates(Action <bool> hotCallBack = null) { AsyncOperationHandle initHandle = Addressables.InitializeAsync(); yield return(initHandle); ////这里的检查更新的目录应该有其他的扩展用法,但是我们这只用来把他当AB的Manifest用 ////所以我们其实只有一个目录,不考虑多个目录的用法 AsyncOperationHandle <List <string> > catalogHandler = Addressables.CheckForCatalogUpdates(false); yield return(catalogHandler); if (catalogHandler.Status != AsyncOperationStatus.Succeeded) { ServerInfoError(); Addressables.Release(catalogHandler); yield break; } List <string> catalogs = (List <string>)catalogHandler.Result; List <IResourceLocator> locators; AsyncOperationHandle CatalogHandle; if (catalogs.Count > 0) { Debug.Log($"需要更新资源的目录"); //下载新的目录 //这个目录里面包含整个项目所有被Addressable管理的资源的地址 //同一份资源有俩个地址,一个是设置的一个是它的hash值 CatalogHandle = Addressables.UpdateCatalogs(catalogs, false); yield return(CatalogHandle); if (CatalogHandle.Status != AsyncOperationStatus.Succeeded) { ServerInfoError(); yield break; } locators = (List <IResourceLocator>)CatalogHandle.Result; } else { //当成AB的manifest去获取一次资源目录 Debug.Log($"不需要更新资源的目录"); IEnumerable <IResourceLocator> ielocators = Addressables.ResourceLocators; locators = new List <IResourceLocator>(); foreach (var locator in ielocators) { locators.Add(locator); } } //检查资源更新 m_Startmono.StartCoroutine(ComputeDownload(locators, hotCallBack)); Addressables.Release(catalogHandler); }
private IEnumerator UpdateCatalogsAsync(List <string> catalogs) { var updateHandle = Addressables.UpdateCatalogs(catalogs, false); yield return(updateHandle); downloadSize = 0; updateKeys = new List <object>(); updateLocators = updateHandle.Result; Addressables.Release(updateHandle); }
private IEnumerator DownLoadUpdate() { var start = DateTime.Now; if (needUpdateCatalogs.Count != 0) { updateHandle = Addressables.UpdateCatalogs(needUpdateCatalogs, false); } yield return(updateHandle); Debug.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); }
//下载catalogs public ETTask <bool> UpdateCatalogs(string catalog) { ETTask <bool> result = ETTask <bool> .Create(); var handle = Addressables.UpdateCatalogs(new string[] { catalog }, false); handle.Completed += (res) => { Addressables.Release(handle); result.SetResult(handle.Status == AsyncOperationStatus.Succeeded); }; return(result); }
public static async UniTask UpdateCatalogAsync(IEnumerable <string> catalogs = null) { var handle = Addressables.UpdateCatalogs(catalogs, false); try { await handle; } finally { Addressables.Release(handle); } }
private void CheckCataLogsCompleted(AsyncOperationHandle <List <string> > checkCataLogsResult) { if (IsAsyncSucceded(checkCataLogsResult)) { if (checkCataLogsResult.Result.Count > 0) { Addressables.UpdateCatalogs().Completed += UpdateCataLogsCompleted; } else { StartDownload(); } } }
private async void DownLoadUpdate() { isUpdating = true; var start = DateTime.Now; //开始下载资源 updateHandle = Addressables.UpdateCatalogs(needUpdateCatalogs, false); await updateHandle.Task; Debug.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); //下载完成 Addressables.Release(updateHandle); isUpdating = false; }
private async void UpdateCatalogs(List <string> catalogList) { AsyncOperationHandle <List <IResourceLocator> > handle = Addressables.UpdateCatalogs(catalogList, false); await handle.Task; if (handle.Status == AsyncOperationStatus.Succeeded) { List <object> keyList = new List <object>(); foreach (IResourceLocator item in handle.Result) { keyList.AddRange(item.Keys); } StartCoroutine(Update(keyList)); } Addressables.Release(handle); }
/// <summary> /// <para>最新のリモートカタログを取得します</para> /// <para>catalogs に null を指定すると、すべてのリモートカタログを更新します</para> /// <para>特定のリモートカタログのみ更新したい場合は catalogs を指定します</para> /// </summary> public AddressablesControllerHandle UpdateCatalogs(IEnumerable <string> catalogs) { var source = new TaskCompletionSource <AddressablesControllerResultCode>(); if (!m_isInitialized) { source.TrySetResult(AddressablesControllerResultCode.FAILURE_NOT_INITIALIZED); return(new AddressablesControllerHandle(source.Task)); } var isFailure = false; void OnComplete(AsyncOperationHandle handle) { m_exceptionHandler -= ExceptionHandler; if (isFailure) { source.TrySetResult(AddressablesControllerResultCode.FAILURE_CANNOT_CONNECTION); return; } if (handle.Status != AsyncOperationStatus.Succeeded) { source.TrySetResult(AddressablesControllerResultCode.FAILURE_UNKNOWN); return; } source.TrySetResult(AddressablesControllerResultCode.SUCCESS); } void ExceptionHandler(Exception exception) { isFailure = true; m_exceptionHandler -= ExceptionHandler; } m_exceptionHandler += ExceptionHandler; var result = Addressables.UpdateCatalogs(catalogs); result.Completed += handle => OnComplete(handle); var controllerHandle = new AddressablesControllerHandle(result, source.Task); return(controllerHandle); }
IEnumerator checkUpdate() { var start = DateTime.Now; AsyncOperationHandle <List <string> > handle = Addressables.CheckForCatalogUpdates(false); yield return(handle); Logger.Log(string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds)); if (handle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = handle.Result; if (catalogs != null && catalogs.Count > 0) { UINoticeTip.Instance.ShowOneButtonTip("更新提示", $"本次更新资源包数量:{catalogs.Count}", "确定", null); yield return(UINoticeTip.Instance.WaitForResponse()); needUpdateRes = true; statusText.text = "正在更新资源..."; slider.normalizedValue = 0f; slider.gameObject.SetActive(true); start = DateTime.Now; AsyncOperationHandle <List <IResourceLocator> > updateHandle = Addressables.UpdateCatalogs(catalogs, true); yield return(updateHandle); Logger.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); yield return(UpdateFinish()); Addressables.Release(updateHandle); } Addressables.Release(handle); } needUpdateRes = false; ChannelManager.instance.resVersion = "112"; ChannelManager.instance.appVersion = "1.0"; yield return(StartGame()); }
public async void UpdateCatalog() { var start = DateTime.Now; var initHandle = Addressables.InitializeAsync(); await initHandle.Task; var checkHandle = Addressables.CheckForCatalogUpdates(false); await checkHandle.Task; Debug.Log(string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds)); Debug.Log($"catalog count: {checkHandle.Result.Count} === check status: {checkHandle.Status}"); if (checkHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = checkHandle.Result; if (catalogs != null && catalogs.Count > 0) { needUpdateRes = true; status_Text.text = "正在更新资源..."; update_Slider.normalizedValue = 0f; update_Slider.gameObject.SetActive(true); start = DateTime.Now; AsyncOperationHandle <List <IResourceLocator> > updateHandle = Addressables.UpdateCatalogs(catalogs, false); await updateHandle.Task; var locators = updateHandle.Result; Debug.Log($"locator count: {locators.Count}"); foreach (var v in locators) { var sizeHandle = Addressables.GetDownloadSizeAsync(v.Keys); await sizeHandle.Task; long size = sizeHandle.Result; Debug.Log($"download size:{size}"); if (size > 0) { //UINoticeTip.Instance.ShowOneButtonTip("更新提示", $"本次更新大小:{size}", "确定", null); //yield return UINoticeTip.Instance.WaitForResponse(); downloadHandle = Addressables.DownloadDependenciesAsync(v.Keys, Addressables.MergeMode.Union); await downloadHandle.Task; Addressables.Release(downloadHandle); } } Debug.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); Addressables.Release(updateHandle); } Addressables.Release(checkHandle); } }
IEnumerator DownloadCatalogs() { var start = DateTime.Now; //开始下载资源 SetState(EUpdateState.StartUpdateCatalogs); catelogHandle = Addressables.UpdateCatalogs(updateCatalogsList, false); catelogHandle.Completed += handle => { MarkNeedDownloadState(true); //下载完成 SetState(EUpdateState.UpdateComplete); Debug.Log($"下载完成Catalogs------------- use time:{(DateTime.Now - start).Milliseconds} ms"); }; yield return(catelogHandle); Addressables.Release(catelogHandle); }
IEnumerator download() { var start = DateTime.Now; //开始下载资源 isUpdating = true; updateHandle = Addressables.UpdateCatalogs(needUpdateCatalogs, false); yield return(updateHandle); Debug.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); //Reg.PlatformAPI.SetAddressableMsg($"下载完成"); //下载完成 isUpdating = false; Addressables.Release(updateHandle); Skip(); //Reg.PlatformAPI.RestartShowSplash(); }
IEnumerator CheckCatalogs() { List<string> catalogsToUpdate = new List<string>(); AsyncOperationHandle<List<string>> checkForUpdateHandle = Addressables.CheckForCatalogUpdates(); checkForUpdateHandle.Completed += op => { catalogsToUpdate.AddRange(op.Result); }; yield return checkForUpdateHandle; if (catalogsToUpdate.Count > 0) { AsyncOperationHandle<List<IResourceLocator>> updateHandle = Addressables.UpdateCatalogs(catalogsToUpdate); yield return updateHandle; Addressables.Release(updateHandle); } Addressables.Release(checkForUpdateHandle); }
public async void UpdateCatalog() { var updateCatalogHandle = Addressables.CheckForCatalogUpdates(false); await updateCatalogHandle.Task; if (updateCatalogHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = updateCatalogHandle.Result; if (catalogs != null && catalogs.Count > 0) { foreach (var catalog in catalogs) { Debug.Log("catalog " + catalog); } Debug.Log("download catalog start "); var updateHandle = Addressables.UpdateCatalogs(catalogs, false); await updateHandle.Task; foreach (var item in updateHandle.Result) { Debug.Log("catalog result " + item.LocatorId); foreach (var key in item.Keys) { Debug.Log("catalog key " + key); } _updateKeys.AddRange(item.Keys); } UpdatePercent.text = "download catalog finish " + updateHandle.Status; Debug.Log("download catalog finish " + updateHandle.Status); } else { UpdatePercent.text = "dont need update catalogs"; Debug.Log("dont need update catalogs"); } } Addressables.Release(updateCatalogHandle); }
void Start() { Debug.Log("StartScene Start"); Addressables.InitializeAsync().Completed += initHandle => { Addressables.CheckForCatalogUpdates().Completed += checkForUpdateHandle => { Debug.Log("CheckForCatalogUpdates complete"); if (checkForUpdateHandle.Result.Count > 0) { foreach (var str in checkForUpdateHandle.Result) { Debug.Log($"Update: {str}"); } Addressables.UpdateCatalogs().Completed += updateHandle => { Debug.Log("UpdateCatalogs complete"); Addressables.GetDownloadSizeAsync(label).Completed += sizeOp => { sizeText.text = sizeOp.Result.ToString(); Debug.Log($"GetDownloadSizeAsync_Completed: size {sizeOp.Result}"); var handle = Addressables.DownloadDependenciesAsync(label); handle.Completed += downloadHandle => { Debug.Log($"Download complete {downloadHandle.Result}"); percentText.text = "100%"; LoadFirstScene(); }; StartCoroutine(PercentTracking(handle)); }; }; } else { Debug.Log("there is no update"); LoadFirstScene(); } }; }; }
public IEnumerator CheckUpdate() { var start = DateTime.Now; gTextField.text = "正在检查资源更新..."; var initHandle = Addressables.InitializeAsync(); yield return(initHandle); var a = Addressables.RuntimePath; var checkHandle = Addressables.CheckForCatalogUpdates(false); yield return(checkHandle); Logger.Log(string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds)); Logger.Log($"catalog count: {checkHandle.Result.Count} === check status: {checkHandle.Status}"); if (checkHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = checkHandle.Result; if (catalogs != null && catalogs.Count > 0) { gTextField.text = "正在更新资源..."; gProgress.visible = true; gProgress.value = 0; start = DateTime.Now; AsyncOperationHandle <List <IResourceLocator> > updateHandle = Addressables.UpdateCatalogs(catalogs, false); yield return(updateHandle); var locators = updateHandle.Result; Logger.Log($"locator count: {locators.Count}"); foreach (var v in locators) { List <object> keys = new List <object>(); keys.AddRange(v.Keys); var sizeHandle = Addressables.GetDownloadSizeAsync(keys); yield return(sizeHandle); long size = sizeHandle.Result; Logger.Log($"download size:{size}"); if (size > 0) { UINoticeWin notice = UINoticeWin.CreateInstance(); notice.ShowOneButton($"本次更新大小:{size}", () => { notice.Hide(); }); yield return(notice.WaitForResponse()); var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union); while (!downloadHandle.IsDone) { float percentage = downloadHandle.PercentComplete; Logger.Log($"download pregress: {percentage}"); gProgress.value = percentage * 100; yield return(null); } Addressables.Release(downloadHandle); } } Logger.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); yield return(UpdateFinish()); Addressables.Release(updateHandle); } Addressables.Release(checkHandle); } yield return(StartGame()); }
/// <summary> /// 检查资源更新 /// </summary> public static void CheckUpdate() { Debug.Log("初始化 Addressables"); var initHandle = Addressables.InitializeAsync(); initHandle.WaitForCompletion(); Debug.Log("检查 Catalogs 更新"); var checkHandle = Addressables.CheckForCatalogUpdates(false); checkHandle.WaitForCompletion(); if (checkHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = checkHandle.Result; if (catalogs != null && catalogs.Count > 0) { Debug.Log("下载 Catalogs 更新"); var updateHandle = Addressables.UpdateCatalogs(catalogs, false); updateHandle.WaitForCompletion(); if (updateHandle.Status == AsyncOperationStatus.Succeeded) { var updateKeys = new List <object>(); foreach (var item in updateHandle.Result) { Debug.Log("Catalog result: " + item.LocatorId); foreach (var key in item.Keys) { Debug.Log("|---Catalog key: " + key); } updateKeys.AddRange(item.Keys); } var totalDownLoadSize = GetDownloadSize(updateKeys); Debug.Log("DownLoad Size:" + (totalDownLoadSize / 1024.0f / 1024.0f).ToString("0.00")); if (totalDownLoadSize > 0) { DownloadAssets(updateKeys); } } else { Debug.Log("检查更新失败,检查联网状态"); } Addressables.Release(updateHandle); } else { Debug.Log("本地 Catalogs 无需更新"); } } else { Debug.Log("检查更新失败,检查联网状态"); } Addressables.Release(checkHandle); }
IEnumerator Start() { //手动初始化AB AsyncOperationHandle <IResourceLocator> initHandle = Addressables.InitializeAsync(); yield return(initHandle); //手动检查更新 var checkHandle = Addressables.CheckForCatalogUpdates(false); yield return(checkHandle); if (checkHandle.Result.Count > 0) { Debug.Log("有更新的CataLog"); ShowInfo("有更新的CataLog Count : " + checkHandle.Result.Count); var updateHandle = Addressables.UpdateCatalogs(checkHandle.Result, false); yield return(updateHandle); List <IResourceLocator> locators = updateHandle.Result; foreach (var locator in locators) { List <object> keys = new List <object>(); keys.AddRange(locator.Keys); var sizeHandle = Addressables.GetDownloadSizeAsync(keys); yield return(sizeHandle); long totalDownloadSize = sizeHandle.Result; Debug.Log("Download Size : " + totalDownloadSize); ShowInfo($"下载大小 : {totalDownloadSize / 1024} K. "); if (totalDownloadSize > 0) { var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union); while (!downloadHandle.IsDone) { yield return(null); } Debug.Log("下载完成!"); ShowInfo("下载完成!"); Addressables.Release(downloadHandle); } } Addressables.Release(updateHandle); } else { Debug.Log("没有要更新的内容"); ShowInfo("没有要更新的内容"); } Addressables.Release(checkHandle); yield return(null); //从AB加载Lua脚本 var Handle = Addressables.LoadAssetAsync <TextAsset>("Assets/LuaScripts/TestLua.lua.txt"); yield return(Handle); //Debug.Log(Handle.Result.text); LuaFile = Handle.Result; //初始化Lua luaenv = new LuaEnv(); luaenv.AddLoader((ref string filename) => { if (filename == "TestLua.lua") //自定义Loader从AB里加载Lua { return(LuaFile.bytes); } return(null); }); luaenv.DoString("require('TestLua.lua')"); var SetInstance = luaenv.Global.Get <Action <TestABUpdate> >("SetInstance"); SetInstance(this); LoadRes = luaenv.Global.Get <Action>("LoadRes"); }
IEnumerator checkUpdate() { var start = DateTime.Now; var initHandle = Addressables.InitializeAsync(); yield return(initHandle); var a = Addressables.RuntimePath; var checkHandle = Addressables.CheckForCatalogUpdates(false); yield return(checkHandle); Logger.Log(string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds)); Logger.Log($"catalog count: {checkHandle.Result.Count} === check status: {checkHandle.Status}"); if (checkHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = checkHandle.Result; if (catalogs != null && catalogs.Count > 0) { needUpdateRes = true; statusText.text = "正在更新资源..."; slider.normalizedValue = 0f; slider.gameObject.SetActive(true); start = DateTime.Now; AsyncOperationHandle <List <IResourceLocator> > updateHandle = Addressables.UpdateCatalogs(catalogs, false); yield return(updateHandle); var locators = updateHandle.Result; Logger.Log($"locator count: {locators.Count}"); foreach (var v in locators) { List <object> keys = new List <object>(); keys.AddRange(v.Keys); var sizeHandle = Addressables.GetDownloadSizeAsync(keys); yield return(sizeHandle); long size = sizeHandle.Result; Logger.Log($"download size:{size}"); if (size > 0) { UINoticeTip.Instance.ShowOneButtonTip("更新提示", $"本次更新大小:{size}", "确定", null); yield return(UINoticeTip.Instance.WaitForResponse()); var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union); while (!downloadHandle.IsDone) { float percentage = downloadHandle.PercentComplete; Logger.Log($"download pregress: {percentage}"); slider.normalizedValue = percentage; yield return(null); } Addressables.Release(downloadHandle); } } Logger.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); yield return(UpdateFinish()); Addressables.Release(updateHandle); } Addressables.Release(checkHandle); } needUpdateRes = false; ChannelManager.instance.resVersion = "112"; ChannelManager.instance.appVersion = "1.0"; yield return(StartGame()); }
/// <summary> /// Update the specified catalogs. /// </summary> /// <param name="catalogs">The set of catalogs to update. If null, all catalogs that have an available update will be updated.</param> /// <param name="autoReleaseHandle">If true, the handle will automatically be released when the operation completes.</param> /// <returns>The operation with the list of updated content catalog data.</returns> public static AsyncOperationHandle <List <IResourceLocator> > UpdateCatalogs(IEnumerable <string> catalogs = null, bool autoReleaseHandle = true) { return(Addressables.UpdateCatalogs(catalogs, autoReleaseHandle)); }
async void CheckUpdate() { Status.text = "正在检测资源更新..."; //初始化Addressable var init = Addressables.InitializeAsync(); await init.Task; //开始连接服务器检查更新 AsyncOperationHandle <List <string> > checkHandle = Addressables.CheckForCatalogUpdates(false); await checkHandle.Task; //检查结束,验证结果 if (checkHandle.Status == AsyncOperationStatus.Succeeded) { List <string> catalogs = checkHandle.Result; if (catalogs != null && catalogs.Count > 0) { Debug.Log("download catalogs start"); var updateHandle = Addressables.UpdateCatalogs(catalogs, false); await updateHandle.Task; Debug.Log("download catalogs finish"); List <object> keys = new List <object>(); foreach (var item in updateHandle.Result) { Debug.Log(item.LocatorId); foreach (var key in item.Keys) { Debug.Log(item.LocatorId + ":" + key); } keys.AddRange(item.Keys); } // 获取下载内容的大小 var sizeHandle = Addressables.GetDownloadSizeAsync(keys); await sizeHandle.Task; long totalDownloadSize = sizeHandle.Result; Debug.Log("下载大小:" + totalDownloadSize); if (totalDownloadSize > 0) { LoadProgress.gameObject.SetActive(true); Status.text = "正在更新中"; Debug.Log("download bundle start"); var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union); while (!downloadHandle.IsDone) { float percent = downloadHandle.PercentComplete; LoadProgress.value = percent; await Task.Yield(); } LoadProgress.value = downloadHandle.PercentComplete; Addressables.Release(downloadHandle); Debug.Log("download bundle finish"); } else { Debug.Log("不需要更新"); } Addressables.Release(updateHandle); //Debug.Log("download bundle start"); //foreach (var item in updateHandle.Result) //{ // var sizeHandle = Addressables.GetDownloadSizeAsync(item.Keys); // await sizeHandle.Task; // if (sizeHandle.Result>0) // { // var downloadHandle = Addressables.DownloadDependenciesAsync(item.Keys, Addressables.MergeMode.Union); // await downloadHandle.Task; // } //} //Debug.Log("download bundle finish"); } else { Debug.Log("不需要更新"); } } Addressables.Release(checkHandle); Debug.Log("CheckUpdate结束"); Status.text = "更新完成"; Create(); }
IEnumerator Process() { Addressables.InitializeAsync().Completed += InitDone; while (isCloudInit != true) { yield return(new WaitForFixedUpdate()); } Addressables.ClearResourceLocators(); Addressables.LoadContentCatalogAsync("https://storage.googleapis.com/cloud_patching_sample/Android/catalog_" + catalogKeyname + ".json").Completed += Cloud_Completed; while (contentCatalogLoaded != true) { yield return(frequencyshort); } Addressables.CheckForCatalogUpdates(false).Completed += (AsyncOperationHandle <List <string> > cb_checkforupdates) => StartCoroutine(CheckCatalogVersion(cb_checkforupdates)); //StartCoroutine(CheckCatalogVersion()); while (isCheckedPatch != true) { yield return(new WaitForFixedUpdate()); } Debug.Log("Patch checked!"); if (requireDownloadPatch) { Debug.Log("Pending download..."); while (pendingDownload != true) { yield return(new WaitForFixedUpdate()); if (proceedDownloadingPatch) { pendingDownload = proceedDownloadingPatch; Debug.Log("patch responded"); } } if (agreedDownload) { Debug.Log("Downloading patch..."); AsyncOperationHandle cb_downloads = Addressables.DownloadDependenciesAsync(downloadKey, false); while (cb_downloads.PercentComplete < 1) { yield return(new WaitForFixedUpdate()); Debug.Log(cb_downloads.PercentComplete); UI_MANAGER.UpdateDynamicContent(cb_downloads.PercentComplete.ToString()); } Debug.Log("Download done" + cb_downloads.Status); yield return(new WaitForSeconds(5f)); UI_MANAGER.RemoveAndClear(); Addressables.UpdateCatalogs().Completed += OnUpdateCatalogs; while (downloadDone != true) { yield return(new WaitForSeconds(0.25f)); } InitialiseAssetsSpawn(); } else { Debug.Log("No downloading..."); } } else { Debug.Log("No patch to update..."); InitialiseAssetsSpawn(); } }
public async Task CheckUpdate() { var start = DateTime.Now; gTextField.text = "正在检查资源更新..."; await Addressables.InitializeAsync().Task; var a = Addressables.RuntimePath; var catalogs = await Addressables.CheckForCatalogUpdates(false).Task; Log.Debug(LogGroups.UI, string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds)); Log.Debug(LogGroups.UI, $"catalog count: {catalogs.Count} === check status: {catalogs}"); if (catalogs != null && catalogs.Count > 0) { gTextField.text = "正在更新资源..."; gProgress.visible = true; gProgress.value = 0; start = DateTime.Now; var locators = await Addressables.UpdateCatalogs(catalogs, false).Task; Log.Debug(LogGroups.UI, $"locator count: {locators.Count}"); foreach (var v in locators) { var size = await Addressables.GetDownloadSizeAsync(v.Keys).Task; Log.Debug(LogGroups.UI, $"download size:{size}"); if (size > 0) { UINoticeWin notice = UINoticeWin.Inst; notice.ShowOneButton($"本次更新大小:{size}", () => { notice.Hide(); }); //等待确定 await notice.WaitForResponse(); var downloadHandle = Addressables.DownloadDependenciesAsync(v.Keys, Addressables.MergeMode.Union); while (!downloadHandle.IsDone) { float percentage = downloadHandle.PercentComplete; Log.Debug(LogGroups.UI, $"download pregress: {percentage}"); gProgress.value = percentage * 100; } Addressables.Release(downloadHandle); } } Log.Debug(LogGroups.UI, string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); UpdateFinish(); Addressables.Release(locators); Addressables.Release(catalogs); } StartGame(); }
private void OnGUI() { if (GUILayout.Button("CheckCatalogUpdate")) { Debug.Log("CheckCatalogUpdate"); var opChecklist = Addressables.CheckForCatalogUpdates(); opChecklist.Completed += handle => { var checkList = handle.Result; Debug.LogFormat("CheckForCatalogUpdates: {0}, Status: {1}", checkList.Count, handle.Status); for (int i = 0; i < checkList.Count; i++) { Debug.LogFormat("[{0}] Check Catalog: {1}", i, checkList[i]); } if (checkList.Count > 0) { var opUpdate = Addressables.UpdateCatalogs(checkList); opUpdate.Completed += operationHandle => { Debug.LogFormat("UpdateCatalogs Status: {0}", operationHandle.Status); if (operationHandle.Status == AsyncOperationStatus.Succeeded) { var locations = operationHandle.Result; Debug.LogFormat("UpdateCatalogs: {0}", locations?.Count ?? 0); for (int i = 0; i < checkList.Count; i++) { Debug.LogFormat("[{0}] Resource Locator: {1}", i, checkList[i]); } } }; } }; } if (GUILayout.Button("Download")) { var opInit = Addressables.InitializeAsync(); opInit.Completed += opInitHandle => { var resLocator = opInitHandle.Result; Debug.Log("Download:" + resLocator.Keys); var opGetDownloadSize = Addressables.GetDownloadSizeAsync(resLocator.Keys); opGetDownloadSize.Completed += handle => { Debug.LogFormat("GetDownloadSizeAsync Status: {0} Size: {1} bytes", handle.GetDownloadStatus(), handle.Result); var allLocations = new List <IResourceLocation>(); foreach (var key in resLocator.Keys) { IList <IResourceLocation> locations; if (resLocator.Locate(key, typeof(object), out locations)) { foreach (var loc in locations) { if (loc.HasDependencies) { allLocations.AddRange(loc.Dependencies); } } } } var allPrimaryKeys = allLocations.Distinct().ToList(); for (int i = 0; i < allPrimaryKeys.Count; i++) { Debug.LogFormat("[{0}]DownloadDependency PrimaryKey: {1}", i, allPrimaryKeys[i]); } var opDownload = Addressables.DownloadDependenciesAsync(allPrimaryKeys); opDownload.Completed += operationHandle => { Debug.LogFormat("DownloadDependenciesAsync: {0}", operationHandle.Result); }; }; }; } if (GUILayout.Button("ClearDependencyCache")) { var opInit = Addressables.InitializeAsync(); opInit.Completed += opInitHandle => { var resLocator = opInitHandle.Result; var allLocations = new List <IResourceLocation>(); foreach (var key in resLocator.Keys) { IList <IResourceLocation> locations; if (resLocator.Locate(key, typeof(object), out locations)) { foreach (var loc in locations) { if (loc.HasDependencies) { allLocations.AddRange(loc.Dependencies); } } } } Debug.LogFormat("ClearDependencyCacheAsync: {0}", allLocations.Count); var opClear = Addressables.ClearDependencyCacheAsync(allLocations, false); opClear.Completed += handle => { Debug.LogFormat("ClearDependencyCacheAsync Completed: {0}", handle.Result); Addressables.Release(handle); }; }; } if (GUILayout.Button("Caching.ClearCache")) { var seconds = 1; var result = Caching.ClearCache(seconds); Debug.LogFormat("Caching.ClearCache: {0}", result); } if (GUILayout.Button("Load")) { Debug.Log("Load"); var handle = Addressables.LoadAssetAsync <GameObject>("Assets/CanNotChangePost/A_1.prefab"); handle.Completed += onLoadDone; handles.Add(handle); } if (GUILayout.Button("UnLoad")) { if (handles.Count > 0) { var handle = handles[handles.Count - 1]; if (handle.IsValid()) { Debug.Log("UnLoad OK"); Addressables.Release(handle); } else { Debug.Log("UnLoad Fail"); } } if (instances.Count > 0) { Destroy(instances[instances.Count - 1]); instances.RemoveAt(instances.Count - 1); } } }