using System; using System.Threading; using UnityEngine; namespace ETModel { public class Init : MonoBehaviour { private readonly OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext(); 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(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); // 下载ab包 await BundleHelper.DownloadBundle(); Game.Hotfix.LoadHotfixAssembly(); // 加载配置 Game.Scene.GetComponent().LoadBundle("config.unity3d"); Game.Scene.AddComponent(); Game.Scene.GetComponent().UnloadBundle("config.unity3d"); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Hotfix.GotoHotfix(); Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } } private void Update() { this.contex.Update(); Game.Hotfix.Update?.Invoke(); Game.EventSystem.Update(); } private void LateUpdate() { Game.Hotfix.LateUpdate?.Invoke(); Game.EventSystem.LateUpdate(); } private void OnApplicationQuit() { Game.Hotfix.OnApplicationQuit?.Invoke(); Game.Close(); } } }