Init.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.Mono;
  17. private void Awake()
  18. {
  19. Instance = this;
  20. #if ENABLE_IL2CPP
  21. this.CodeMode = CodeMode.ILRuntime;
  22. #endif
  23. System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  24. {
  25. Log.Error(e.ExceptionObject.ToString());
  26. };
  27. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  28. DontDestroyOnLoad(gameObject);
  29. Log.ILog = new UnityLogger();
  30. Options.Instance = new Options();
  31. this.codeLoader = CodeLoader.Instance;
  32. }
  33. private void Start()
  34. {
  35. this.codeLoader.Start();
  36. }
  37. private void Update()
  38. {
  39. this.codeLoader.Update();
  40. }
  41. private void LateUpdate()
  42. {
  43. this.codeLoader.LateUpdate();
  44. }
  45. private void OnApplicationQuit()
  46. {
  47. this.codeLoader.OnApplicationQuit();
  48. }
  49. }
  50. }