| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using System.IO;
- using System.Threading;
- using Google.Protobuf;
- using UnityEngine;
- namespace ETModel
- {
- public class Init : MonoBehaviour
- {
- 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<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();
- Log.Debug($"111111111111111111111111111111111111111");
- await Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);
- Log.Debug($"111111111111111111111111111111111111112");
- Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
- }
- catch (Exception e)
- {
- Log.Error(e);
- }
- }
- private void Update()
- {
- OneThreadSynchronizationContext.Instance.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();
- }
- }
- }
|