public static async Task DownloadInstallPacket() { if (Define.IsAsync) { try { using (InstallPacketDownloaderComponent installPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>()) { if (null == installPacketDownloaderComponent) { return; } Game.EventSystem.Run(EventIdType.InstallPacketBegin); await installPacketDownloaderComponent.DownloadApkAsync(); } Game.EventSystem.Run(EventIdType.InstallPacketFinish); } catch (Exception e) { Log.Error(e); } } }
public override void OnShow(object obj) { mBundleDownloaderComponent = obj as BundleDownloaderComponent; mInstallPacketDownloaderComponent = obj as InstallPacketDownloaderComponent; // StartLoading(); }
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; }
public static string InstallPacketPath() { InstallPacketDownloaderComponent installPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>(); if (null != installPacketDownloaderComponent) { return(Path.Combine(PathHelper.AppHotfixResPath, installPacketDownloaderComponent.remoteInstallPacketConfig.ApkName)); } return(Path.Combine(PathHelper.AppHotfixResPath, "crazypoker.apk")); }
public override void Dispose() { if (IsDisposed) { return; } mBundleDownloaderComponent = null; mInstallPacketDownloaderComponent = null; base.Dispose(); }
public static async Task CheckInstallPacket() { if (Define.IsAsync) { try { using (InstallPacketDownloaderComponent installPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>() ?? Game.Scene.AddComponent <InstallPacketDownloaderComponent>()) { await installPacketDownloaderComponent.StartAsync(); } } catch (Exception e) { Log.Error(e); } } }
public static bool NeedInstallPacket() { // if (UnityEngine.Application.platform == RuntimePlatform.WindowsEditor || UnityEngine.Application.platform == RuntimePlatform.OSXEditor) // return false; #if UNITY_EDITOR return(false); #endif InstallPacketDownloaderComponent installPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>(); if (null == installPacketDownloaderComponent) { return(false); } #if UNITY_ANDROID if (installPacketDownloaderComponent.remoteInstallPacketConfig.Android.Equals(UnityEngine.Application.version)) { return(false); } #elif UNITY_IOS #if APPStore // AppStore专用 if (installPacketDownloaderComponent.remoteInstallPacketConfig.IOSAppStore.Equals(UnityEngine.Application.version)) { return(false); } #else if (installPacketDownloaderComponent.remoteInstallPacketConfig.IOS.Equals(UnityEngine.Application.version)) { return(false); } #endif #endif return(true); }
public override void OnHide() { mBundleDownloaderComponent = null; mInstallPacketDownloaderComponent = null; }
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); } }