Init.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Reflection;
  3. using System.Threading;
  4. using UnityEngine;
  5. namespace ET
  6. {
  7. public interface IEntry
  8. {
  9. void Start();
  10. void Update();
  11. void LateUpdate();
  12. void OnApplicationQuit();
  13. }
  14. public class Init: MonoBehaviour
  15. {
  16. private IEntry entry;
  17. private void Awake()
  18. {
  19. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  20. DontDestroyOnLoad(gameObject);
  21. Assembly modelAssembly = null;
  22. if (Define.IsEditor)
  23. {
  24. UnityEngine.Debug.Log("unity editor mode!");
  25. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  26. {
  27. string assemblyName = $"{assembly.GetName().Name}.dll";
  28. if (assemblyName != "Unity.ModelView.dll")
  29. {
  30. continue;
  31. }
  32. modelAssembly = assembly;
  33. break;
  34. }
  35. }
  36. else
  37. {
  38. UnityEngine.Debug.Log("unity standalone mode!");
  39. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  40. {
  41. string assemblyName = $"{assembly.GetName().Name}.dll";
  42. if (assemblyName != "Unity.ModelView.dll")
  43. {
  44. continue;
  45. }
  46. modelAssembly = assembly;
  47. break;
  48. }
  49. }
  50. if (!Define.UseLua)
  51. {
  52. Type initType = modelAssembly.GetType("ET.MonoEntry");
  53. this.entry = Activator.CreateInstance(initType) as IEntry;
  54. }
  55. else
  56. {
  57. Type initType = this.GetType().Assembly.GetType("ET.LuaEntry");
  58. this.entry = Activator.CreateInstance(initType) as IEntry;
  59. }
  60. }
  61. private void Start()
  62. {
  63. this.entry.Start();
  64. }
  65. private void Update()
  66. {
  67. this.entry.Update();
  68. }
  69. private void LateUpdate()
  70. {
  71. this.entry.LateUpdate();
  72. }
  73. private void OnApplicationQuit()
  74. {
  75. this.entry.OnApplicationQuit();
  76. }
  77. }
  78. }