private async System.Threading.Tasks.Task TestWifiUi() { UIComponent uiComponent = Game.Scene.GetComponent <UIComponent>(); UI uiLoading = uiComponent.Get(UIType.UILoading); var uiLoadingComponent = uiLoading.GetComponent <UILoadingComponent>(); var x = 2048 / 1024f; //如果大于1m才弹提示 if (x > 1) { while (!VideoUtil.videoFinished) { await 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; } }
public static ActionAwait GetAwaiter(this ActionEvent actionEvent) { return(new ActionAwait(actionEvent)); }
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); } } }