Init.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Threading;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. // 1 mono模式 2 ILRuntime模式 3 mono热重载模式
  6. public enum CodeMode
  7. {
  8. Mono = 1,
  9. ILRuntime = 2,
  10. Reload = 3,
  11. }
  12. public class Init: MonoBehaviour
  13. {
  14. public static Init Instance;
  15. private CodeLoader codeLoader;
  16. public CodeMode CodeMode = CodeMode.ILRuntime;
  17. private void Awake()
  18. {
  19. Instance = this;
  20. System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  21. {
  22. Log.Error(e.ExceptionObject.ToString());
  23. };
  24. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  25. DontDestroyOnLoad(gameObject);
  26. Log.ILog = new UnityLogger();
  27. Options.Instance = new Options();
  28. this.codeLoader = CodeLoader.Instance;
  29. }
  30. private void Start()
  31. {
  32. this.codeLoader.Start();
  33. }
  34. private void Update()
  35. {
  36. this.codeLoader.Update();
  37. }
  38. private void LateUpdate()
  39. {
  40. this.codeLoader.LateUpdate();
  41. }
  42. private void OnApplicationQuit()
  43. {
  44. this.codeLoader.OnApplicationQuit();
  45. }
  46. }
  47. }