Init.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. UnityEngine.Debug.Log("unity editor mode!");
  23. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  24. {
  25. string assemblyName = $"{assembly.GetName().Name}.dll";
  26. if (assemblyName != "Unity.ModelView.dll")
  27. {
  28. continue;
  29. }
  30. modelAssembly = assembly;
  31. break;
  32. }
  33. Type initType = modelAssembly.GetType("ET.MonoEntry");
  34. this.entry = Activator.CreateInstance(initType) as IEntry;
  35. }
  36. private void Start()
  37. {
  38. this.entry.Start();
  39. }
  40. private void Update()
  41. {
  42. this.entry.Update();
  43. }
  44. private void LateUpdate()
  45. {
  46. this.entry.LateUpdate();
  47. }
  48. private void OnApplicationQuit()
  49. {
  50. this.entry.OnApplicationQuit();
  51. }
  52. }
  53. }