public static async ETTask DownloadBundle() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene. AddComponent <BundleDownloaderComponent>()) { //跟远程对比 确认哪些文件需要进行更新 压入待更新的队列中 await bundleDownloaderComponent.StartAsync(); //派发进行开始加载的事件 Game.EventSystem.Run(EventIdType.LoadingBegin); //就是从队列里取出要下载的文件信息 然后进行下载 await bundleDownloaderComponent.DownloadAsync(); } Game.EventSystem.Run(EventIdType.LoadingFinish); //以往记录所有AB信息的AB包 都是以平台名称定义的 那是因为父目录是以平台名称进行定义 //而ET中,AB文件存放的父目录是StreamingAssets 而非平台名称 //所以无论什么平台,记录所有AB信息的文件都叫StreamingAssets Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); //缓存分析依赖的Mainifest文件 ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene .GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }
public static async Task DownloadBundle() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { // 下载Version进行MD5对比 await bundleDownloaderComponent.StartAsync(); // 根据对比结果进行自动下载更新 await bundleDownloaderComponent.DownloadAsync(); } // 下载成功后读取AssetBundleManifest数据并且缓存起来 Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); // 完成更新 FGUI.GetShowingUI <UI_CheckUpdate>()?.SetState(DownloadState.Done); } catch (Exception e) { Log.Error(e); } } else { // 编辑器模式直接跳到完成 FGUI.GetShowingUI <UI_CheckUpdate>()?.SetState(DownloadState.Done); } }
/// <summary> /// 下载AB包 /// </summary> /// <returns></returns> public static async Task DownloadBundle() { if (Define.IsAsync) //如果不是在编辑器模式下 { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { await bundleDownloaderComponent.StartAsync(); //确认需要更新的AB包 Game.EventSystem.Run(EventIdType.LoadingBegin); //发出开始加载事件消息 await bundleDownloaderComponent.DownloadAsync(); //开始下载AB包 } Game.EventSystem.Run(EventIdType.LoadingFinish); //发出加载完成事件消息 //同步加载StreamingAssets ab包 Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); //拿到StreamingAssets ab包的依赖文件AssetBundleManifest ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }
public static async ETTask DownloadBundle() { if (Define.IsAsync) { #if true try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { await bundleDownloaderComponent.StartAsync(); Game.EventSystem.Run(EventIdType.LoadingBegin); await bundleDownloaderComponent.DownloadAsync(); } Game.EventSystem.Run(EventIdType.LoadingFinish); } catch (Exception e) { Log.Error(e); } #endif #if !UNITY_EDITOR Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); #endif } await ETTask.CompletedTask; }
public static async ETTask DownloadBundle() { if (!Define.UseEditorResouces) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { await bundleDownloaderComponent.StartAsync(); Game.EventSystem.Run(EventIdType.LoadingBegin); return; await bundleDownloaderComponent.DownloadAsync(); var loadingCpt = Game.Scene.GetComponent <UIComponent>().Get(UIType.InitLoadingUI)?.GetComponent <UILoadingComponent>(); if (loadingCpt != null) { loadingCpt.TargetValue = 1; } } // Game.EventSystem.Run(EventIdType.LoadingFinish); //Debug.LogError("xxx"); Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }
public static async Task DownloadBundle() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>()) { Game.EventSystem.Run(EventIdType.LoadingBegin); Loading = true; await bundleDownloaderComponent.DownloadAsync(); } // Game.EventSystem.Run(EventIdType.LoadingFinish); DownloadBundleFinish(); } catch (Exception e) { Log.Error(e); } } }
/// <summary> /// /// </summary> /// <returns></returns> public static async ETTask DownloadBundle() { //通过预定义符判断是否是异步下载 if (Define.IsAsync) { try { //获取AssetsBudle下载组件,从web端下载,并对比md5码,对比资源 using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { //拿到远程和本地所有不需要热更的bundle await bundleDownloaderComponent.StartAsync(); //通过事件系统调用显示加载界面 Game.EventSystem.Run(EventIdType.LoadingBegin); await bundleDownloaderComponent.DownloadAsync(); } Game.EventSystem.Run(EventIdType.LoadingFinish); Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }
public override void OnShow(object obj) { mBundleDownloaderComponent = obj as BundleDownloaderComponent; mInstallPacketDownloaderComponent = obj as InstallPacketDownloaderComponent; // StartLoading(); }
/// <summary> /// 下载资源信息(编辑器模式下不会运行) /// </summary> /// <returns></returns> public static async ETTask DownloadBundle() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { await bundleDownloaderComponent.StartAsync(); Log.Debug("运行 登录开始"); Game.EventSystem.Run(EventIdType.LoadingBegin); await bundleDownloaderComponent.DownloadAsync(); } Game.EventSystem.Run(EventIdType.LoadingFinish); Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }
private async void StartLoading() { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = this.InstanceId; while (true) { await timerComponent.WaitAsync(1000); if (this.InstanceId != instanceId) { //Remove break; } if (null == mBundleDownloaderComponent && null == mInstallPacketDownloaderComponent) { //Hide break; } if (null != mBundleDownloaderComponent) { textContent.text = $"{mBundleDownloaderComponent.Progress}%"; } if (null != mInstallPacketDownloaderComponent) { textContent.text = $"{mInstallPacketDownloaderComponent.Progress}%"; } } mBundleDownloaderComponent = null; mInstallPacketDownloaderComponent = null; }
private async ETTask HotfixUpdate() { BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); for (int i = 0; i < GameVersionsConfigMgr.Ins.ServerGameVersionsConfig.ToyGameVersionsArray.Count; i++) { for (int j = 0; j < GameVersionsConfigMgr.Ins.LocalGameVersionsConfig.ToyGameVersionsArray.Count; j++) { //对比服务器版本 if (GameVersionsConfigMgr.Ins.ServerGameVersionsConfig.ToyGameVersionsArray[i].Id == GameVersionsConfigMgr.Ins.LocalGameVersionsConfig.ToyGameVersionsArray[j].Id) { //如果本地版本比服务器版本 高或者相同 就不用更新 if (GameVersionsConfigMgr.Ins.LocalGameVersionsConfig.ToyGameVersionsArray[j].Version >= GameVersionsConfigMgr.Ins.ServerGameVersionsConfig.ToyGameVersionsArray[i].Version) { continue; } BundleDownSchedule bundleDownSchedule = new BundleDownSchedule(); UndateResActionInvoke(bundleDownSchedule, i + 1, GameVersionsConfigMgr.Ins.ServerGameVersionsConfig.ToyGameVersionsArray.Count); await bundleDownloaderComponent.StartAsync(GameVersionsConfigMgr.Ins.ServerGameVersionsConfig .ToyGameVersionsArray[i], bundleDownSchedule); } } } GameVersionsConfigMgr.Ins.SaveServerVersionsToLocal(); //更新完成 存储服务器版本信息到本地 }
public override void Dispose() { if (IsDisposed) { return; } mBundleDownloaderComponent = null; mInstallPacketDownloaderComponent = null; base.Dispose(); }
public static async ETTask DownloadBundle() { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { Game.EventSystem.Run(EventIdType.CheckForUpdateBegin); Game.EventSystem.Run(EventIdType.CreateLoadingUI); await bundleDownloaderComponent.StartUpdate(); Log.Info("资源热更完成,进入大厅"); } }
public void Awake() { bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); ReferenceCollector referenceCtrl = this.GetParent <UI>().GameObject.GetComponent <ReferenceCollector>(); UpNumText = GetParent <UI>().GameObject.TryGetInChilds <Text>("UpNumText"); updateSlider = GetParent <UI>().GameObject.TryGetInChilds <Slider>("UpdateSlider"); updateSlider.value = 0f; _AppVersionText = referenceCtrl.Get <GameObject>("AppVersionText").Get <Text>(); _ResouceVersionText = referenceCtrl.Get <GameObject>("ResouceVersionText").Get <Text>(); }
public async void Start() { _AppVersionText.text = ""; _ResouceVersionText.text = ""; updateSlider.value = 0f; _IsCountDown = false; Log.Debug("首先获取后台配置,成功后再进入更新流程"); var isSuccess = await RequestWebConfigURL("http://39.98.214.224:666/syskuma/api/getGameConfig"); if (!isSuccess) { Log.Error("获取配置失败(可能是超时,可能是解析异常)!!"); return; } var webConfig = ClientComponent.Instance.webConfig; if (webConfig != null) { this._ResouceVersionText.text = $"资源版本号:{webConfig.zybbh}"; this._AppVersionText.text = $"APP版本号:{webConfig.dbbh}"; } BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); if (bundleDownloaderComponent == null) { return; } UpNumText.text = ""; _IsDownload = bundleDownloaderComponent.TotalSize - bundleDownloaderComponent.CurrVersionBytes > 0; if (!_IsDownload) { TargetValue = 1f; } else { OnOkButton(); } }
public static bool NeedDownloadBundle() { BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); if (null == bundleDownloaderComponent) { return(false); } if (bundleDownloaderComponent.bundles.Count == 0) { return(false); } return(true); }
public static async Task CheckDownloadBundle() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>() ?? Game.Scene.AddComponent <BundleDownloaderComponent>()) { await bundleDownloaderComponent.StartAsync(); } } catch (Exception e) { Log.Error(e); } } }
public static async Task StartDownLoadResources() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.AddComponent <BundleDownloaderComponent>()) { await bundleDownloaderComponent.StartAsync(); } Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundle("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = Game.Scene.GetComponent <ResourcesComponent>().GetAsset <AssetBundleManifest>("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e.ToString()); } } }
private async ETVoid StartAsync(FUICheckForResUpdateComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = self.InstanceId; while (true) { await timerComponent.WaitAsync(1); if (self.InstanceId != instanceId) { return; } BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); if (bundleDownloaderComponent == null) { continue; } if (bundleDownloaderComponent.Updater.Step == Step.Versions) { self.FUICheackForResUpdate.updateInfo.text = "正在为您检查资源更新..."; } if (bundleDownloaderComponent.Updater.Step == Step.Prepared) { self.FUICheackForResUpdate.updateInfo.text = "检查更新完毕"; } if (bundleDownloaderComponent.Updater.Step == Step.Download) { self.FUICheackForResUpdate.updateInfo.text = "正在为您更新资源:" + $"{bundleDownloaderComponent.Updater.UpdateProgress}%"; if (bundleDownloaderComponent.Updater.UpdateProgress >= 100) { self.FUICheackForResUpdate.updateInfo.text = "资源更新完成,祝您游戏愉快。"; } } self.FUICheackForResUpdate.processbar.TweenValue(bundleDownloaderComponent.Updater.UpdateProgress, 0.1f); } }
public override async void Start(UILoadingComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); while (true) { await timerComponent.WaitAsync(1000); if (self.IsDisposed) { return; } BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); if (bundleDownloaderComponent == null) { continue; } self.text.text = $"{bundleDownloaderComponent.Progress}%"; } }
public async ETVoid StartAsync(UILoadingComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = self.InstanceId; while (true) { await timerComponent.WaitAsync(1000); if (self.InstanceId != instanceId) { return; } BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); if (bundleDownloaderComponent == null) { continue; } self.text.text = $"{bundleDownloaderComponent.Progress}%"; } }
public override async void Start(UILoadingComponent self) { Log.Debug("UiLoadingComponentStartSystem : Start"); TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = self.InstanceId; while (true) { await timerComponent.WaitAsync(1000); if (self.InstanceId != instanceId) { return; } BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); if (bundleDownloaderComponent == null) { continue; } self.text.text = $"{bundleDownloaderComponent.Progress}%"; } }
private async ETVoid StartAsync() { try { Application.runInBackground = true; #if UNITY_IOS || UNITY_ANDROID // Application.runInBackground = true; // Application.targetFrameRate = 60; Screen.sleepTimeout = SleepTimeout.NeverSleep; #endif #if LOG_ZSX var nodes = GameObject.Find("LoginCanvas"); if (nodes != null) { var node = nodes.GetComponentsInChildren <RectTransform>(); for (int i = 0; i < node.Length; i++) { node[i].gameObject.SetActive(false); } nodes.SetActive(true); } #endif SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <LocalResourcesComponent>(); // Game.Scene.AddComponent<PlayerComponent>(); // Game.Scene.AddComponent<UnitComponent>(); Game.Scene.AddComponent <NetHttpComponent>(); Game.Scene.AddComponent <UIComponent>(); Game.Scene.AddComponent <NetLineSwitchComponent>(); #if UNITY_IOS TimerComponent iOSTimerComponent = Game.Scene.GetComponent <TimerComponent>(); while (true) { await iOSTimerComponent.WaitAsync(200); if (UnityEngine.Application.internetReachability != NetworkReachability.NotReachable) { break; } } #endif // 安装包更新 await InstallPacketHelper.CheckInstallPacket(); if (InstallPacketHelper.NeedInstallPacket()) { InstallPacketDownloaderComponent mInstallPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>(); if (null != mInstallPacketDownloaderComponent) { bool mWaitting = true; string[] mArr = mInstallPacketDownloaderComponent.remoteInstallPacketConfig.Msg.Split(new string[] { "@%" }, StringSplitOptions.None); int mTmpLanguage = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.KEY_LANGUAGE, 2); if (mTmpLanguage < 0) { mTmpLanguage = 0; } int mGroup = mArr.Length / 3; if (mTmpLanguage < mGroup) { UIComponent.Instance.ShowNoAnimation(UIType.UIDialog, new UIDialogComponent.DialogData() { type = UIDialogComponent.DialogData.DialogType.Commit, title = mArr[mTmpLanguage], content = mArr[mTmpLanguage + mGroup], contentCommit = mArr[mTmpLanguage + 2 * mGroup], contentCancel = string.Empty, actionCommit = () => { mWaitting = false; }, actionCancel = null }); TimerComponent mUpdateTimerComponent = Game.Scene.GetComponent <TimerComponent>(); while (mWaitting) { await mUpdateTimerComponent.WaitAsync(200); } UIComponent.Instance.Remove(UIType.UIDialog); } } #if UNITY_ANDROID switch (UnityEngine.Application.internetReachability) { case NetworkReachability.ReachableViaCarrierDataNetwork: // "当前为运行商网络(2g、3g、4g)" string mTmpMsg = string.Empty; int mTmpLanguage = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.KEY_LANGUAGE, 2); switch (mTmpLanguage) { case 0: mTmpMsg = $"当前使用移动数据,需要消耗{mInstallPacketDownloaderComponent.remoteInstallPacketConfig.ApkSize / (1024 * 1024)}M流量,是否继续下载?"; break; case 1: mTmpMsg = $"The current use of mobile data, need to consume {mInstallPacketDownloaderComponent.remoteInstallPacketConfig.ApkSize / (1024 * 1024)} M, whether to download?"; break; case 2: mTmpMsg = $"當前使用移動數據,需要消耗{mInstallPacketDownloaderComponent.remoteInstallPacketConfig.ApkSize / (1024 * 1024)}M流量,是否繼續下載?"; break; } Game.Scene.GetComponent <UIComponent>().Show(UIType.UICarrierDataNetwork, new UICarrierDataNetworkComponent.UICarrierDataNetworkData() { Msg = mTmpMsg, Callback = async() => { await InstallPacketHelper.DownloadInstallPacket(); // Log.Debug($"下载完啦!"); // todo 调起安装 NativeManager.OpenApk(InstallPacketHelper.InstallPacketPath()); } }, null, 0); break; case NetworkReachability.ReachableViaLocalAreaNetwork: // wifi网络 await InstallPacketHelper.DownloadInstallPacket(); // todo 调起安装 NativeManager.OpenApk(InstallPacketHelper.InstallPacketPath()); return; } #elif UNITY_IOS UnityEngine.Application.OpenURL(mInstallPacketDownloaderComponent.remoteInstallPacketConfig.IOSUrl); Application.Quit(); #endif return; } // 下载ab包 await BundleHelper.CheckDownloadBundle(); BundleHelper.IsDownloadBundleFinish = false; if (BundleHelper.NeedDownloadBundle()) { #if UNITY_IOS bool AppStorePack = false; #if APPStore AppStorePack = true; #endif InstallPacketDownloaderComponent mInstallPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>(); if (!mInstallPacketDownloaderComponent.remoteInstallPacketConfig.CheckRes && AppStorePack) { BundleHelper.DownloadBundleFinish(); } else #endif { BundleDownloaderComponent mBundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>(); switch (UnityEngine.Application.internetReachability) { case NetworkReachability.ReachableViaCarrierDataNetwork: // "当前为运行商网络(2g、3g、4g)" string mTmpMsg = string.Empty; int mTmpLanguage = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.KEY_LANGUAGE, 2); switch (mTmpLanguage) { case 0: mTmpMsg = $"当前使用移动数据,需要消耗{mBundleDownloaderComponent.TotalSize / (1024 * 1024)}M流量,是否继续下载?"; break; case 1: mTmpMsg = $"The current use of mobile data, need to consume {mBundleDownloaderComponent.TotalSize / (1024 * 1024)} M, whether to download?"; break; case 2: mTmpMsg = $"當前使用移動數據,需要消耗{mBundleDownloaderComponent.TotalSize / (1024 * 1024)}M流量,是否繼續下載?"; break; } Game.Scene.GetComponent <UIComponent>().ShowNoAnimation(UIType.UICarrierDataNetwork, new UICarrierDataNetworkComponent.UICarrierDataNetworkData() { Msg = mTmpMsg, Callback = async() => { await BundleHelper.DownloadBundle(); BundleHelper.IsDownloadBundleFinish = true; }, }); TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); while (true) { await timerComponent.WaitAsync(1000); if (BundleHelper.IsDownloadBundleFinish) { break; } } Game.Scene.GetComponent <UIComponent>().Remove(UIType.UICarrierDataNetwork); break; case NetworkReachability.ReachableViaLocalAreaNetwork: // wifi网络 await BundleHelper.DownloadBundle(); break; } } } else { BundleHelper.DownloadBundleFinish(); } Game.Hotfix.LoadHotfixAssembly(); // 加载配置 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatcherComponent>(); Game.Hotfix.GotoHotfix(); // Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
public override void OnHide() { mBundleDownloaderComponent = null; mInstallPacketDownloaderComponent = null; }
public static async Task StartDownLoadResources() { if (Define.isUseAssetBundle) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>()) { var t = bundleDownloaderComponent.LoadInfo(); UIComponent uiComponent = Game.Scene.GetComponent <UIComponent>(); UI uiLoading = uiComponent.Get(UIType.UILoading); var uiLoadingComponent = uiLoading.GetComponent <UILoadingComponent>(); uiLoadingComponent.DownLoadInfo = bundleDownloaderComponent.DownloadInfo; bundleDownloaderComponent.BundleRealProgress = uiLoadingComponent.BundleRealDownload; bundleDownloaderComponent.BundleEachFrameProgress = uiLoadingComponent.BundleDownloadFrames; uiLoadingComponent.UpdateProgress = bundleDownloaderComponent.UpdateProgress; var needDown = await t; if (needDown) { var x1 = uiLoadingComponent.DownLoadInfo.TotalSize / 1024; var x = x1 / 1024f; //如果大于1m 不是wifi才弹提示 if (x > 1 /*&& Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork*/) { //while (!VideoUtil.videoFinished) // await UniRx.Async.UniTask.DelayFrame(1); var actionEvent = new ActionEvent(); //弹提示. var trans = uiLoadingComponent.view.transform.Find("ConfirmWindow"); var tip = new UIUpdateTip(trans); //取两位小数 int j = (int)(x * 100); x = j / 100f; tip.SetInfo($"当前不是wifi环境, 更新需要消耗{x}M流量,\n是否更新 ? (点击取消将退出游戏)"); tip.OnConfirm = () => { trans.gameObject.SetActive(false); actionEvent.Dispatch(); }; tip.OnCancel = () => { Define.QuitApplication(); return; }; await actionEvent; } } await bundleDownloaderComponent.Down(); uiLoadingComponent.DownLoadInfo.IsEnd = true; } //Game.Scene.GetComponent<ResourcesComponent>().LoadOneBundle("StreamingAssets"); await Game.Scene.GetComponent <ResourcesComponent>().LoadOneBundleAsync("StreamingAssets"); ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }
public static async Task StartDownLoadResources() { if (Define.IsAsync) { try { using (BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>()) { var t = bundleDownloaderComponent.LoadInfo(); UIComponent uiComponent = Game.Scene.GetComponent <UIComponent>(); UI uiLoading = uiComponent.Get(UIType.UILoading); var uiLoadingComponent = uiLoading.GetComponent <UILoadingComponent>(); uiLoadingComponent.DownLoadInfo = bundleDownloaderComponent.DownloadInfo; bundleDownloaderComponent.BundleRealProgress = uiLoadingComponent.BundleRealDownload; bundleDownloaderComponent.BundleEachFrameProgress = uiLoadingComponent.BundleDownloadFrames; uiLoadingComponent.UpdateProgress = bundleDownloaderComponent.UpdateProgress; var needDown = await t; if (needDown) { while (!VideoUtil.videoFinished) { await UniRx.Async.UniTask.DelayFrame(1); } var sizeKB = bundleDownloaderComponent.TotalSize / 1024; var sizeM = sizeKB / 1024f; //如果大于1m 不是wifi才弹提示 if (sizeM > 1 && Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork) { while (!VideoUtil.videoFinished) { await UniRx.Async.UniTask.DelayFrame(1); } var actionEvent = new ActionEvent(); //弹提示. var trans = uiLoadingComponent.view.transform.Find("ConfirmWindow"); var tip = new UIUpdateTip(trans); //取两位小数 int j = (int)(sizeM * 100); sizeM = j / 100f; //50138140 var tips = "Currently not connected to WIFI, please choose whether to download the update."; tip.SetTitle("Tips"); tip.SetInfo(tips);//$"当前不是wifi环境, 更新需要消耗{sizeM}M流量,\n是否更新 ? (点击取消将退出游戏)"); tip.OnConfirm = () => { trans.gameObject.SetActive(false); actionEvent.Dispatch(); }; tip.OnCancel = () => { Define.QuitApplication(); return; }; await actionEvent; } await bundleDownloaderComponent.Down(); uiLoadingComponent.DownLoadInfo.IsEnd = true; SaveVersion(); } /*若想在播放开场视频时就开始使用wifi下载,注掉下面 * while(!VideoUtil.videoFinished) * await UniRx.Async.UniTask.DelayFrame(1);*/ uiLoadingComponent.UpdateProgressNew(0.9f); } //await Game.Scene.GetComponent<ResourcesComponent>().LoadOneBundleAsync("StreamingAssets"); //ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest"); } catch (Exception e) { Log.Error(e); } } }