Init.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 CodeMode CodeMode = CodeMode.Mono;
  15. private void Awake()
  16. {
  17. #if ENABLE_IL2CPP
  18. this.CodeMode = CodeMode.ILRuntime;
  19. #endif
  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. CodeLoader.Instance.CodeMode = this.CodeMode;
  29. }
  30. private void Start()
  31. {
  32. CodeLoader.Instance.Start();
  33. }
  34. private void Update()
  35. {
  36. CodeLoader.Instance.Update();
  37. }
  38. private void LateUpdate()
  39. {
  40. CodeLoader.Instance.LateUpdate();
  41. }
  42. private void OnApplicationQuit()
  43. {
  44. CodeLoader.Instance.OnApplicationQuit();
  45. }
  46. }
  47. }