IEnumerator Start() { LoggerHelper.Instance.Startup(); JsManager.Instance.Startup(); //初始化FairyGUI GRoot.inst.SetContentScaleFactor(1280, 720, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight); UIPackage.unloadBundleByFGUI = false; NTexture.CustomDestroyMethod = (Texture t) => { Addressables.Release(t); Logger.Log(".... release addressable: " + t.name); }; UIObjectFactory.SetPackageItemExtension(LaunchPage.URL, typeof(LaunchPage)); UIObjectFactory.SetPackageItemExtension(UINoticeWin.URL, typeof(UINoticeWin)); //加载FairyGUI Package AsyncOperationHandle <TextAsset> handle = Addressables.LoadAssetAsync <TextAsset>(fairy_package); yield return(handle); TextAsset pkgAsset = handle.Result; UIPackage.AddPackage( pkgAsset.bytes, "game", async(string name, string extension, Type type, PackageItem ite) => { Logger.Log($"{name}, {extension}, {type.ToString()}, {ite.ToString()}"); if (type == typeof(Texture)) { Texture t = await Addressables.LoadAssetAsync <Texture>(name + extension).Task; ite.owner.SetItemAsset(ite, t, DestroyMethod.Custom); } }); Addressables.Release(handle); //加载更新界面 launchPage = LaunchPage.CreateInstance(); launchPage.Show(); //Test UINoticeWin notice = UINoticeWin.CreateInstance(); notice.ShowOneButton("test test", () => { notice.Hide(); }); yield return(notice.WaitForResponse()); // 开始更新 if (launchPage != null) { StartCoroutine(launchPage.CheckUpdate()); } yield break; }
async Task Start() { LoggerHelper.Instance.Startup(); JsManager.Instance.Startup(); //初始化FairyGUI GRoot.inst.SetContentScaleFactor(1280, 720, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight); UIPackage.unloadBundleByFGUI = false; UIObjectFactory.SetPackageItemExtension(LaunchPage.URL, typeof(LaunchPage)); UIObjectFactory.SetPackageItemExtension(UINoticeWin.URL, typeof(UINoticeWin)); //加载FairyGUI Package ResourceManager.init(); await ResourceManager.LoadFairyGUIPackage("common_fui.bytes", "common"); await ResourceManager.LoadFairyGUIPackage("launch_fui.bytes", "launch"); //加载更新界面 launchPage = LaunchPage.CreateInstance(); launchPage.Show(); //Test UINoticeWin notice = UINoticeWin.CreateInstance(); notice.ShowOneButton("test test", () => { notice.Hide(); }); await notice.WaitForResponse(); // 开始更新 if (launchPage != null) { await launchPage.CheckUpdate(); } }
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()); }
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; Logger.Log(string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds)); Logger.Log($"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; Logger.Log($"locator count: {locators.Count}"); foreach (var v in locators) { List <object> keys = new List <object>(); keys.AddRange(v.Keys); var size = await Addressables.GetDownloadSizeAsync(keys).Task; Logger.Log($"download size:{size}"); if (size > 0) { UINoticeWin notice = UINoticeWin.CreateInstance(); notice.ShowOneButton($"本次更新大小:{size}", () => { notice.Hide(); }); //等待确定 await 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; } Addressables.Release(downloadHandle); } } Logger.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); UpdateFinish(); Addressables.Release(locators); Addressables.Release(catalogs); } StartGame(); }