Init.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Threading;
  3. using KYFramework;
  4. using UnityEngine;
  5. using Logger = KYFramework.Logger;
  6. namespace VRPlatform
  7. {
  8. public class Init : MonoBehaviour
  9. {
  10. private void Awake()
  11. {
  12. try
  13. {
  14. SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
  15. DontDestroyOnLoad(gameObject);
  16. Game.EventSystem.Add(typeof(Init).Assembly);
  17. Game.EventSystem.Add(typeof(Entity).Assembly);
  18. #if UNITY_EDITOR
  19. Logger.Instance.ILog = new ULogger();
  20. #else
  21. Logger.Instance.ILog = new NLogger("Client", "NLog/NLog.config");
  22. #endif
  23. Game.EventSystem.Publish(new StartApp());
  24. }
  25. catch (Exception e)
  26. {
  27. Debug.Log(e);
  28. }
  29. }
  30. private void Update()
  31. {
  32. OneThreadSynchronizationContext.Instance.Update();
  33. Game.EventSystem.Update();
  34. }
  35. private void LateUpdate()
  36. {
  37. Game.EventSystem.LateUpdate();
  38. }
  39. private void OnApplicationQuit()
  40. {
  41. Game.Close();
  42. }
  43. }
  44. }