using System; using System.Threading; using CommandLine; using UnityEngine; namespace ET { public class Init: MonoBehaviour { public static Init Instance; public GlobalConfig GlobalConfig; private void Awake() { Instance = this; DontDestroyOnLoad(gameObject); AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); // 命令行参数 Options options = null; string[] args = "".Split(" "); Parser.Default.ParseArguments(args) .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}")) .WithParsed(o => { options = o; }); Game.AddSingleton(options); Game.AddSingleton(); Game.AddSingleton().ILog = new UnityLogger(); Game.AddSingleton(); Game.AddSingleton(); Game.AddSingleton(); Game.AddSingleton(); ETTask.ExceptionHandler += Log.Error; Game.AddSingleton().Start(); } private void Update() { Game.Update(); } private void LateUpdate() { Game.LateUpdate(); } private void OnApplicationQuit() { Game.Close(); } } }