private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); ClientConfigHelper.SetConfigHelper(); Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); //Log.Info(typeof(Core).Assembly.ToString()); Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); //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>(); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); // 网络同步方式组件 Game.Scene.AddComponent <NetSyncComponent, SyncType>(SyncType.State); //Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.InitSceneStart); //Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); //通过反射机制,获取特性来加载DLL里面的类 Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <TimerComponent>(); //全局配置组件(热更新服务器地址等) Game.Scene.AddComponent <GlobalConfigComponent>(); //网络连接组件(跟服务器通信) Game.Scene.AddComponent <NetOuterComponent>(); //资源管理组件(热更新资源管理,AB包) Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); //UI管理组件 Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); // 加载热更新代码DLL 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>(); //保存User信息及ID Game.Scene.AddComponent <ClientComponent>(); //执行热更,热更层的入口 Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async void Start() { try { if (Application.unityVersion != "2017.1.3p2") { Log.Warning($"请使用Unity2017.1.3p2, 下载地址:\n https://beta.unity3d.com/download/744dab055778/UnityDownloadAssistant-2017.1.3p2.exe?_ga=2.42497696.443074145.1521714954-1119432033.1499739574"); } SynchronizationContext.SetSynchronizationContext(this.contex); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <BehaviorTreeComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ClientFrameComponent>(); Game.Scene.AddComponent <UIComponent>(); //斗地主客户端自定义全局组件 //用于保存玩家本地数据 Game.Scene.AddComponent <ClientComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); 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 <MessageDispatherComponent>(); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async void Start() { try { if (Application.unityVersion != "2017.1.0p5") { Log.Warning($"当前版本:{Application.unityVersion}, 最好使用运行指南推荐版本!"); } SynchronizationContext.SetSynchronizationContext(this.contex); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <BehaviorTreeComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ClientFrameComponent>(); Game.Scene.AddComponent <UIComponent>(); //斗地主客户端自定义全局组件 //用于保存玩家本地数据 Game.Scene.AddComponent <ClientComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); 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 <MessageDispatherComponent>(); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async void Start() { try { if (!Application.unityVersion.StartsWith("2017.4")) { Log.Error($"新人请使用Unity2017.4版本,减少跑demo遇到的问题! 下载地址:\n https://unity3d.com/cn/unity/qa/lts-releases?_ga=2.227583646.282345691.1536717255-1119432033.1499739574"); } SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ClientFrameComponent>(); // Game.Scene.AddComponent<UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); 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 <MessageDispatherComponent>(); //新Ui Log.Debug("加载UI框架"); Game.Scene.AddComponent <UIManagerComponent>(); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async void Start() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); //帧同步服务器 //Game.Scene.AddComponent<ClientFrameComponent>(); Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); 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 <MessageDispatherComponent>(); //加载声音,讲道理这里也要添加一个组件,声音的中间层 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("audiocontroller.unity3d"); GameObject audiocontroller = (GameObject)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("audiocontroller.unity3d", "AudioController"); GameObject.Instantiate(audiocontroller); //加载字体组件 Game.Scene.AddComponent <FontComponent>(); Game.Hotfix.GotoHotfix(); //给热更层发消息 //Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { //上下文同步 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); //禁止销毁 在切换场景的时候 DontDestroyOnLoad(gameObject); //遍历Model的程序集 缓存各个加了特性标签的对象 Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <TimerComponent>(); //计时器 Game.Scene.AddComponent <GlobalConfigComponent>(); //全局配置 Game.Scene.AddComponent <NetOuterComponent>(); //外网组件 提供创建网络通道 在每个通道内部维护消息是收发处理 Game.Scene.AddComponent <ResourcesComponent>(); //资源组件 提供AB加载 Game.Scene.AddComponent <PlayerComponent>(); //玩家组件 提供玩家管理 Game.Scene.AddComponent <UnitComponent>(); //单位组件 它的实体加了HideInHierarchy 表示在层级视图中隐藏 Game.Scene.AddComponent <UIComponent>(); //UI组件 // 下载ab包 await BundleHelper.DownloadBundle(); //加载热更新代码 Game.Hotfix.LoadHotfixAssembly(); // 加载资源配置 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); UnitConfig unit = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); //操作码 协议号 Game.Scene.AddComponent <OpcodeTypeComponent>(); //消息分发 Game.Scene.AddComponent <MessageDispatcherComponent>(); //初始化IL Game.Hotfix.GotoHotfix(); //测试热修复订阅事件 Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { 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 <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <EventCenterComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); Game.Hotfix.LoadHotfixAssembly(); //新Ui // Log.Debug("加载UI框架"); Game.Scene.AddComponent <UIManagerComponent>(); // 加载配置 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>(); //加载行为树 Log.Debug("开始加载行为树"); Game.Scene.AddComponent <BeahaviacComponent>(); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <ResourcesAsyncComponent>(); Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <UIComponent>(); if (!Assets.development) { //下载地址 //Assets.downloadURL = @"http://192.168.50.2:9191/"; Assets.downloadURL = GlobalConfigComponent.Instance.GlobalProto.AssetBundleServerUrl; //Assets.downloadURL = @"file://" + Application.dataPath + "/../../LoaclServer/"; // 下载ab包 await BundleHelper.DownloadBundle(); } 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(); } catch (Exception e) { Log.Error(e); } }
private async void Start() { try { if (Application.unityVersion != "2017.4.3f1") { Log.Error($"新人请使用Unity2017.4.3f1,减少跑demo遇到的问题! 下载地址:\n https://download.unity3d.com/download_unity/21ae32b5a9cb/UnityDownloadAssistant-2017.4.3f1.exe"); } SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); //Game.Scene.AddComponent<BehaviorTreeComponent>(); //Game.Scene.AddComponent<PlayerComponent>(); //Game.Scene.AddComponent<UnitComponent>(); //Game.Scene.AddComponent<ClientFrameComponent>(); Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); 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 <MessageDispatherComponent>(); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 检测当前AB是否需要加载 /// </summary> /// <param name="AbName"></param> /// <returns></returns> private void CheckABLoad(string AbName, VersionConfig remoteVersionConfig, VersionConfig streamingVersionConfig) { //则将本地MD5与远程MD5对比 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { if (fileVersionInfo.File == AbName.StringToAB()) { string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); if (fileVersionInfo.MD5 != localFileMD5) { this.bundles.Enqueue(fileVersionInfo.File); this.TotalSize += fileVersionInfo.Size; } break; } } }
private async ETVoid StartAsync() { try { 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 <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <FUIPackageComponent>(); Game.Scene.AddComponent <FUIComponent>(); Game.Scene.AddComponent <FUIInitComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); Game.Hotfix.LoadHotfixAssembly(null, null); // 加载配置 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>(); ILHelper.InitILRuntime(Game.Hotfix.appDomain); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async void OnButtonClick_Enter() { switch (this.downloadState) { case DownloadState.Begin: case DownloadState.Retry: // 下载 SetState(DownloadState.Quit); await BundleHelper.DownloadBundle(); break; case DownloadState.Done: // 完成 Done(); break; case DownloadState.Quit: // 退出游戏 Application.Quit(); break; } }
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 async Task StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/Version.txt"; Log.Error("server version=" + versionUrl); await webRequestAsync.DownloadAsync(versionUrl); remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); Log.Warning("server version json=" + JsonHelper.ToJson(remoteVersionConfig)); } } catch (Exception e) { throw new Exception($"url: {versionUrl}", e); } // 获取HotfixResPath目录的Version.txt string versionPath = Path.Combine($"file://{PathHelper.AppHotfixResPath}", "Version.txt"); Log.Debug("local version=" + versionPath); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())//未下载的 { try { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); } catch (Exception e) { Log.Debug($"获取本地目录的Version.txt 失败! Message: {e.Message}"); } } // 获取streaming目录的Version.txt if (null == streamingVersionConfig) { // string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt"); versionPath = Path.Combine($"file://{PathHelper.AppResPath}", "Version.txt"); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>()) { try { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); } catch (Exception e) { Log.Debug($"获取本地目录的Version.txt 失败! Message: {e.Message}"); streamingVersionConfig = new VersionConfig(); } } var verLocal = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");//创建路径 if (Directory.Exists(PathHelper.AppHotfixResPath) == false) { Directory.CreateDirectory(PathHelper.AppHotfixResPath); } using (FileStream fs = new FileStream(verLocal, FileMode.Create))//创建 { VersionConfig t = new VersionConfig() { Version = remoteVersionConfig.Version, TotalSize = 0, ABSecurity = remoteVersionConfig.ABSecurity, FileInfoDict = new Dictionary <string, FileVersionInfo>() }; var json = JsonHelper.ToJson(t); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json); fs.Write(bytes, 0, bytes.Length); } } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath); if (directoryInfo.Exists) { FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } if (fileInfo.Name == "Version.txt") { continue; } fileInfo.Delete(); } } else { directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); if (fileVersionInfo.MD5 == localFileMD5 || fileVersionInfo.File == "Version.txt")//txt不去对比md5 { continue; } bundles.Enqueue(fileVersionInfo.File); TotalSize += fileVersionInfo.Size; } }
private async void Start() { try { if (!Application.unityVersion.StartsWith("2017.4")) { Log.Error($"新人请使用Unity2017.4版本,减少跑demo遇到的问题! 下载地址:\n https://unity3d.com/cn/unity/qa/lts-releases?_ga=2.227583646.282345691.1536717255-1119432033.1499739574"); } //线程同步队列,对socket的回调进行排序调用 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); //这个类会一直保留 //通过反射机制,获取特性得到DLL里面的类 Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); //全局配置组件 (热更新资源地址,服务器ID端口) Game.Scene.AddComponent <GlobalConfigComponent>(); //网络通信组件(和服务器通信) Game.Scene.AddComponent <NetOuterComponent>(); //资源管理组件 (热更资源的管理,AB包) Game.Scene.AddComponent <ResourcesComponent>(); //玩家组建 DEMO使用的 Game.Scene.AddComponent <PlayerComponent>(); //DEMO使用的 Game.Scene.AddComponent <UnitComponent>(); //帧同步组件 Game.Scene.AddComponent <ClientFrameComponent>(); //UI组件 Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); //加载热更新资源 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 <MessageDispatherComponent>(); //执行热更层的代码 Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); ClientConfigHelper.SetConfigHelper(); Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); //添加指定与网络组件 Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); //添加UI组件 Game.Scene.AddComponent <UIComponent>(); Game.Scene.AddComponent <GamerComponent>(); Game.Scene.AddComponent <FUIPackageComponent>(); Game.Scene.AddComponent <FUIComponent>(); //添加消息分发组件MessageDispatcherComponent Game.Scene.AddComponent <MessageDispatcherComponent>(); /* * //Test05 * //练习1 * * Game.Scene.AddComponent<OpcodeTestComponent>(); * await BundleHelper.DownloadBundle(); * Game.EventSystem.Load(); * * //练习2 * Game.Scene.AddComponent<TimerComponent>(); * Game.Scene.AddComponent<FrameTestComponent>(); * * //练习3 * TestRoom room = ComponentFactory.Create<TestRoom>(); * room.AddComponent<TimeTestComponent>(); * room.GetComponent<TimeTestComponent>().Run(Typebehavior.Waiting, 5000); * * * * Game.EventSystem.Load(); * * //Test09 * //练习1 * Game.Scene.AddComponent<Test0901Component>(); * Game.EventSystem.Run(UIEventType.EndLandLogin); */ //执行斗地主初始事件,也就是创建LandLogin界面 Game.EventSystem.Run(UIEventType.FUILandInitSceneStart); //Game.EventSystem.Run(UIEventType.LandInitLobby); //测试发送给服务端一条文本消息 //Session session = Game.Scene.GetComponent<NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); //G2C_TestMessage g2CTestMessage = (G2C_TestMessage) await session.Call(new C2G_TestMessage() { Info = "==>>服务端的朋友,你好!收到请回答" }); } catch (Exception e) { Log.Error(e); } }
public async ETTask StartAsync() { alreadyDownloadBytes = 0; TotalSize = 0; CurrVersionBytes = 0; string versionUrl = ""; versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt"; Log.Debug($"当前资源为AB模式,远程版本文件路径:" + versionUrl); try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { await webRequestAsync.DownloadAsync(versionUrl); CurrVersionBytes += (long)webRequestAsync.Request.downloadedBytes; // 获取远程的Version.txt remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); } } catch (Exception e) { Log.Error($"download version.txt error: {e}"); return; } // 获取streaming目录的Version.txt VersionConfig streamingVersionConfig; string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt"); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>()) { Log.Debug("本地版本文件路径:" + versionPath); await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath); if (directoryInfo.Exists) { FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } if (fileInfo.Name == "Version.txt") { continue; } fileInfo.Delete(); } } else { directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); //如果MD5相同,且当前项目不含有这个文件 if (fileVersionInfo.MD5 == localFileMD5) { continue; } if (IsFilterRes(fileVersionInfo.File)) { continue; } this.bundles.Enqueue(fileVersionInfo.File); this.TotalSize += fileVersionInfo.Size; } }
//对比本地资源和服务器资源 public async ETTask StartAsync(string fileFoldr = "", string versionName = "Version.txt") { downloadFoldr = fileFoldr; // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { versionUrl = Path.Combine(GlobalConfigComponent.Instance.GlobalProto.GetUrl(), "StreamingAssets", downloadFoldr, versionName); await webRequestAsync.DownloadAsync(versionUrl); remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); } } catch (Exception e) { pLoserCall?.Invoke(e.ToString()); throw new Exception($"url: {versionUrl}", e); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(PathHelper.AppHotfixResPath, downloadFoldr)); if (directoryInfo.Exists) { FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } if (fileInfo.Name == versionName) { continue; } fileInfo.Delete(); } } else { directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 string localFileMD5 = BundleHelper.GetBundleMD5(fileVersionInfo.File); if (fileVersionInfo.MD5 == localFileMD5) { continue; } this.bundles.Enqueue(fileVersionInfo.File); this.TotalSize += fileVersionInfo.Size; } await DownloadAsync(); }
private async ETVoid StartAsync() { try { // SynchronizationContext类是用于多线程之间通信的一个类,其在通讯中充当了个传输者的角色 //异步Socket每次接收一步就会单独分出一个线程 //这里使异步方法全部会回调到主线程,进行Socket线程队列同步 //最后让收到的所有消息都是有序的 //搞懂 SynchronizationContext(第一部分)【翻译】:https://www.cnblogs.com/lzxianren/p/SynchronizationContext.html SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); //我懂了?!! //挂载DebuggerComponent gameObject.AddComponent <DebuggerComponent>(); //通知Unity这个GameObject永远不会销毁 DontDestroyOnLoad(gameObject); //反射当前所有dll,添加到反射系统 Model.dll 类型Init的程序集 Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); //计时器 Game.Scene.AddComponent <TimerComponent>(); //全局配置数据(服务器的链接IP、资源服务器的HTTP地址) Game.Scene.AddComponent <GlobalConfigComponent>(); //联网组件(进行服务器通讯用的组件) Game.Scene.AddComponent <NetOuterComponent>(); //热更新资源(资源管理,AB包) Game.Scene.AddComponent <ResourcesComponent>(); //所有玩家(用户信息、等) Game.Scene.AddComponent <PlayerComponent>(); //游戏单元 (Demo用的:骷髅模型) Game.Scene.AddComponent <UnitComponent>(); //ET的UI框架组件(掌管着ET的UI) Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); //读取热更代码 ILRuntime VM Game.Hotfix.LoadHotfixAssembly(); // 加载配置 描所有的带config.unity3d的ConfigAttribute标签的配置包(配置文件在Res/Config文件夹,并带有config.untiy3d标签) Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); //消息代码识别码组件(操作码等) Game.Scene.AddComponent <OpcodeTypeComponent>(); //消息分发组件 收到消息后由哪个handler调用处理 Game.Scene.AddComponent <MessageDispatcherComponent>(); //进入热更层,执行ETHotfix.Init() Game.Hotfix.GotoHotfix(); //测试 分发数值监听事件 Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 拿到远程和本地不需要热更的bundle,添加到bundles /// </summary> /// <returns></returns> public async ETTask StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { //web资源服务器地址 本地为http://127.0.0.1:8080/PC/ (PC为平台) versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt"; Log.Debug("web资源服务器地址" + versionUrl); //开始下载版本信息 await webRequestAsync.DownloadAsync(versionUrl); //将下载到的远程版本配置信息反序列化为VersionConfig remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); Log.Debug("热更新到的VersionConfig:" + JsonHelper.ToJson(this.remoteVersionConfig)); } } catch (Exception e) { throw new Exception($"url: {versionUrl}", e); } // 获取客户端的Version.txt // 获取streaming目录的Version.txt VersionConfig streamingVersionConfig; //地址合并 拿到本地版本信息文件路径 string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt"); Log.Debug("本地Version.txt地址:" + versionPath); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>()) { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); Log.Debug("本地Version.txt内容:" + streamingVersionConfig); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath); Log.Debug("应用程序外部资源路径存放路径(热更新资源路径):" + PathHelper.AppHotfixResPath); if (directoryInfo.Exists) { //有此AppHotfixResPath我呢见驾就获取其中文件 FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { //远程版本文件中如果有此文件直接跳过 if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } //是远程版本文件也跳过 if (fileInfo.Name == "Version.txt") { continue; } //删除远程版本文件中不存在的资源 fileInfo.Delete(); } } else { //热更新资源路径不存在则创建此路径 directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 (远程文件对应的本地文件的MD5) string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); if (fileVersionInfo.MD5 == localFileMD5) { continue; } //添加到bundles队列 this.bundles.Enqueue(fileVersionInfo.File); //总计大小 this.TotalSize += fileVersionInfo.Size; } }
private async ETVoid StartAsync() { try { BsonHelper.Init(); ForwardRenderBridge.Instance.Init(); SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); DontDestroyOnLoad(MainCamera); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <NumericWatcherComponent>(); fixedUpdate = new FixedUpdate() { UpdateCallback = () => Game.EventSystem.FixedUpdate() }; Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <CoroutineLockComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <FUIPackageComponent>(); Game.Scene.AddComponent <FUIComponent>(); Game.Scene.AddComponent <FUIInitComponent>(); //用户输入管理组件 Game.Scene.AddComponent <UserInputComponent>(); Game.Scene.AddComponent <CampAllocManagerComponent>(); Game.Scene.AddComponent <MouseTargetSelectorComponent>(); Game.Scene.AddComponent <GameObjectPool>(); // 下载ab包 await BundleHelper.DownloadBundle(); Game.Hotfix.LoadHotfixAssembly(); // 加载配置 Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatcherComponent>(); Game.Scene.AddComponent <HeroBaseDataRepositoryComponent>(); Game.Scene.AddComponent <B2S_DebuggerComponent>(); Game.Hotfix.GotoHotfix(); Game.Scene.AddComponent <NP_SyncComponent>(); Game.Scene.AddComponent <NP_TreeDataRepository>(); Game.Scene.AddComponent <CDComponent>(); Game.Scene.AddComponent <SoundComponent>(); Game.Scene.GetComponent <SoundComponent>().PlayMusic("Sound_BGM", 0, 0.4f, true); //战斗系统的事件系统组件 Game.Scene.AddComponent <BattleEventSystem>(); //UnitFactory.NPBehaveTestCreate(); } catch (Exception e) { Log.Error(e); } }
public async ETTask StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { //UnityWebRequest UnityWebRequest www下载 versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt"; //Log.Debug(versionUrl); await webRequestAsync.DownloadAsync(versionUrl); remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); //Log.Debug(JsonHelper.ToJson(this.VersionConfig)); } } catch (Exception e) { throw new Exception($"url: {versionUrl}", e); } // 获取streaming目录的Version.txt VersionConfig streamingVersionConfig; string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt"); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>()) { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath); //如果存放热更新资源的文件夹存在 if (directoryInfo.Exists) { //获取到里面的所有子文件 FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { //就是远程下载下来的版本文件 json反序列化成一个实体类 FileInfoDict这个字典就包含了所有AB文件信息 if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } if (fileInfo.Name == "Version.txt") { continue; } //为什么要删除掉远程不存在的文件呢 主要是为了避免加载资源出错 资源重复 会导致到报错 fileInfo.Delete(); } } //如果保存热更新资源的文件夹不存在的话 通过Create进行创建 else { directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 跟我们本地的文件进行MD5对比 string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); //如果相等 就忽略 表示两个版本中 这个文件并未做任何改动 if (fileVersionInfo.MD5 == localFileMD5) { continue; } //如果两个文件的MD5不一致 把要下载的文件 压入到队列 this.bundles.Enqueue(fileVersionInfo.File); //下载的总大小也加上这个文件的大小 this.TotalSize += fileVersionInfo.Size; } }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); // 全局配置 GlobalProto.txt // {"AssetBundleServerUrl":"http://127.0.0.1:8080/","Address":"127.0.0.1:10002"} Game.Scene.AddComponent <GlobalConfigComponent>(); // 网络组件连接组件(跟服务器通信) Game.Scene.AddComponent <NetOuterComponent>(); // 资源管理组件(热更新资源的管理,AB包) Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <TankComponent>(); Game.Scene.AddComponent <NumericWatcherComponent>(); // FGUI包管理 Game.Scene.AddComponent <FUIPackageComponent>(); // FGUI组件管理 Game.Scene.AddComponent <FUIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); await Game.Scene.GetComponent <FUIPackageComponent>().CreateConstPackage(); // 加载热更新 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>(); // 执行热更层Hotfix的入口 Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 开始下载远程Version文件进行本地对比 确认需要下载的AB包文件 /// </summary> /// <returns></returns> public async Task StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { //从Resources文件夹读取“VK”预制体上的TXT文档取得AB资源服务区地址 得到最新的Version.txt versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt"; //Log.Debug(versionUrl); await webRequestAsync.DownloadAsync(versionUrl); //下载资源 remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); //Log.Debug(JsonHelper.ToJson(this.VersionConfig)); } } catch (Exception e) { throw new Exception($"url: {versionUrl}", e); } // 获取streaming目录的Version.txt VersionConfig streamingVersionConfig; //得到本地Version文件地址 string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt"); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>()) { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); } // 删掉远程不存在的文件 获取本地热更新文件夹 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath); if (directoryInfo.Exists) //如果有这个文件夹 { //得到文件夹内所有文件 FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { //新的版本配置表中没有这个文件 就删除此文件 if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } if (fileInfo.Name == "Version.txt") { continue; } fileInfo.Delete(); } } else { //否则就创建新的热更新资源文件夹 directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 本地 string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); if (fileVersionInfo.MD5 == localFileMD5) { continue; } this.bundles.Enqueue(fileVersionInfo.File); //需要重新下载的AB包的名字 this.TotalSize += fileVersionInfo.Size; //需要下载的资源的总大小 } }
public async ETTask StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt"; //Log.Debug(versionUrl); await webRequestAsync.DownloadAsync(versionUrl); remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); //Log.Debug(JsonHelper.ToJson(this.VersionConfig)); } } catch (Exception e) { throw new Exception($"url: {versionUrl}", e); } // 获取streaming目录的Version.txt VersionConfig streamingVersionConfig; string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt"); using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>()) { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath); if (directoryInfo.Exists) { FileInfo[] fileInfos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name)) { continue; } if (fileInfo.Name == "Version.txt") { continue; } fileInfo.Delete(); } } else { directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); if (fileVersionInfo.MD5 == localFileMD5) { continue; } this.bundles.Enqueue(fileVersionInfo.File); this.TotalSize += fileVersionInfo.Size; } }
public async ETTask StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>()) { versionUrl = PathHelper.RemoteLoadPath + "/Version.txt"; await webRequestAsync.DownloadAsync(versionUrl); remoteVersionConfigData = webRequestAsync.Request.downloadHandler.data; remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text); } } catch (Exception e) { throw new Exception($"url: {versionUrl}", e); } try { // 获取streaming目录的Version.txt VersionConfig streamingVersionConfig; string versionPath = PathHelper.SavePath + "Version.txt"; if (File.Exists(versionPath)) { streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(File.ReadAllText(versionPath)); } else { streamingVersionConfig = new VersionConfig(); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.SavePath); if (directoryInfo.Exists) { FileInfo[] fileInfos = directoryInfo.GetFiles(); int directoryFolderLength = directoryInfo.FullName.Length; foreach (FileInfo fileInfo in fileInfos) { if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.FullName.Substring(directoryFolderLength))) { continue; } if (fileInfo.Name == "Version.txt") { continue; } fileInfo.Delete(); } } else { directoryInfo.Create(); } // 对比MD5 foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values) { // 对比md5 string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File); if (fileVersionInfo.MD5 == localFileMD5) { hasDonwLoadedFile.Add(fileVersionInfo.File, fileVersionInfo); continue; } this.bundles.Enqueue(fileVersionInfo.File); this.TotalSize += fileVersionInfo.Size; } } catch (Exception ex) { UnityEngine.Debug.LogError(ex.StackTrace); } }