| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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<Options>(args)
- .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
- .WithParsed(o => { options = o; });
-
- Game.AddSingleton(options);
- Game.AddSingleton<TimeInfo>();
- Game.AddSingleton<Logger>().ILog = new UnityLogger();
- Game.AddSingleton<ObjectPool>();
- Game.AddSingleton<IdGenerater>();
- Game.AddSingleton<EventSystem>();
- Game.AddSingleton<Root>();
-
- ETTask.ExceptionHandler += Log.Error;
- Game.AddSingleton<CodeLoader>().Start();
- }
- private void Update()
- {
- Game.Update();
- }
- private void LateUpdate()
- {
- Game.LateUpdate();
- }
- private void OnApplicationQuit()
- {
- Game.Close();
- }
- }
- }
|