YooAssetsDriver.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Diagnostics;
  2. using UnityEngine;
  3. namespace YooAsset
  4. {
  5. internal class YooAssetsDriver : MonoBehaviour
  6. {
  7. #if UNITY_EDITOR
  8. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
  9. private static void OnRuntimeInitialize()
  10. {
  11. LastestUpdateFrame = 0;
  12. }
  13. #endif
  14. private static int LastestUpdateFrame = 0;
  15. void Update()
  16. {
  17. DebugCheckDuplicateDriver();
  18. YooAssets.Update();
  19. }
  20. #if UNITY_EDITOR
  21. void OnApplicationQuit()
  22. {
  23. YooAssets.OnApplicationQuit();
  24. }
  25. #endif
  26. [Conditional("DEBUG")]
  27. private void DebugCheckDuplicateDriver()
  28. {
  29. if (LastestUpdateFrame > 0)
  30. {
  31. if (LastestUpdateFrame == Time.frameCount)
  32. YooLogger.Warning($"There are two {nameof(YooAssetsDriver)} in the scene. Please ensure there is always exactly one driver in the scene.");
  33. }
  34. LastestUpdateFrame = Time.frameCount;
  35. }
  36. }
  37. }