Init.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. using System.Threading;
  5. using UnityEngine;
  6. namespace ET
  7. {
  8. public class Init : MonoBehaviour
  9. {
  10. private void Start()
  11. {
  12. try
  13. {
  14. SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
  15. DontDestroyOnLoad(gameObject);
  16. string[] assemblyNames = { "Unity.Model.dll", "Unity.Hotfix.dll", "Unity.ModelView.dll", "Unity.HotfixView.dll" };
  17. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  18. {
  19. string assemblyName = assembly.ManifestModule.Name;
  20. if (!assemblyNames.Contains(assemblyName))
  21. {
  22. continue;
  23. }
  24. Game.EventSystem.Add(assembly);
  25. }
  26. Game.EventSystem.Publish(new EventType.AppStart());
  27. }
  28. catch (Exception e)
  29. {
  30. Log.Error(e);
  31. }
  32. }
  33. private void Update()
  34. {
  35. OneThreadSynchronizationContext.Instance.Update();
  36. Game.EventSystem.Update();
  37. }
  38. private void LateUpdate()
  39. {
  40. Game.EventSystem.LateUpdate();
  41. }
  42. private void OnApplicationQuit()
  43. {
  44. Game.Close();
  45. }
  46. }
  47. }