Init.cs 1.1 KB

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