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>(); // 下载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.ToString()); } }
private async void Start() { try { if (Application.unityVersion != "2017.1.0p5") { Log.Error("请使用Unity2017.1.0p5版本"); } DontDestroyOnLoad(gameObject); Instance = this; Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <OpcodeTypeComponent>(); 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.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); Game.Scene.AddComponent <MessageDispatherComponent>(); #if ILRuntime Log.Debug("run in ilruntime mode"); this.AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d"); Game.EventSystem.LoadHotfixDll(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d"); ILHelper.InitILRuntime(); this.start = new ILStaticMethod("Hotfix.Init", "Start", 0); this.update = new ILStaticMethod("Hotfix.Init", "Update", 0); this.lateUpdate = new ILStaticMethod("Hotfix.Init", "LateUpdate", 0); this.onApplicationQuit = new ILStaticMethod("Hotfix.Init", "OnApplicationQuit", 0); #else Log.Debug("run in mono mode"); Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d"); Game.EventSystem.LoadHotfixDll(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d"); Type hotfixInit = Game.EventSystem.HotfixAssembly.GetType("Hotfix.Init"); this.start = new MonoStaticMethod(hotfixInit, "Start"); this.update = new MonoStaticMethod(hotfixInit, "Update"); this.lateUpdate = new MonoStaticMethod(hotfixInit, "LateUpdate"); this.onApplicationQuit = new MonoStaticMethod(hotfixInit, "OnApplicationQuit"); #endif // 进入热更新层 this.start.Run(); Game.EventSystem.Run(EventIdType.InitSceneStart); } catch (Exception e) { Log.Error(e.ToString()); } }
public async ETTask StartAsync() { // 获取远程的Version.txt string versionUrl = ""; try { using (UnityWebRequestAsync webRequestAsync = EntityFactory.Create <UnityWebRequestAsync>(this.Domain)) { versionUrl = Define.GetUrl() + "StreamingAssets/" + "Version.txt"; //Log.Debug(versionUrl); await webRequestAsync.DownloadAsync(versionUrl); remoteVersionConfig = JsonUtility.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(Define.AppResPath4Web, "Version.txt"); using (UnityWebRequestAsync request = EntityFactory.Create <UnityWebRequestAsync>(this.Domain)) { await request.DownloadAsync(versionPath); streamingVersionConfig = JsonUtility.FromJson <VersionConfig>(request.Request.downloadHandler.text); } // 删掉远程不存在的文件 DirectoryInfo directoryInfo = new DirectoryInfo(Define.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; } }