Init.cs 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Reflection;
  3. using UnityEngine;
  4. namespace ET
  5. {
  6. public interface IEntry
  7. {
  8. void Start();
  9. void Update();
  10. void LateUpdate();
  11. void OnApplicationQuit();
  12. }
  13. public class Init: MonoBehaviour
  14. {
  15. private IEntry entry;
  16. private void Awake()
  17. {
  18. DontDestroyOnLoad(gameObject);
  19. Assembly modelAssembly = null;
  20. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  21. {
  22. string assemblyName = assembly.ManifestModule.Name;
  23. if (assemblyName != "Unity.ModelView.dll")
  24. {
  25. continue;
  26. }
  27. modelAssembly = assembly;
  28. break;
  29. }
  30. Type initType = modelAssembly.GetType("ET.Entry");
  31. this.entry = Activator.CreateInstance(initType) as IEntry;
  32. }
  33. private void Start()
  34. {
  35. this.entry.Start();
  36. }
  37. private void Update()
  38. {
  39. this.entry.Update();
  40. }
  41. private void LateUpdate()
  42. {
  43. this.entry.LateUpdate();
  44. }
  45. private void OnApplicationQuit()
  46. {
  47. this.entry.OnApplicationQuit();
  48. }
  49. }
  50. }