Init.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(ThreadSynchronizationContext.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. ProtobufHelper.Init();
  27. Game.Options = new Options();
  28. Game.EventSystem.Publish(new EventType.AppStart());
  29. }
  30. catch (Exception e)
  31. {
  32. Log.Error(e);
  33. }
  34. }
  35. private void Update()
  36. {
  37. ThreadSynchronizationContext.Instance.Update();
  38. Game.EventSystem.Update();
  39. }
  40. private void LateUpdate()
  41. {
  42. Game.EventSystem.LateUpdate();
  43. }
  44. private void OnApplicationQuit()
  45. {
  46. Game.Close();
  47. }
  48. }
  49. }