com.alicizax.unity.tuyoogam.../Runtime/YooAssetsDriver.cs

44 lines
1.1 KiB
C#
Raw Normal View History

2025-01-09 11:31:04 +08:00
using System.Diagnostics;
using UnityEngine;
namespace YooAsset
{
internal class YooAssetsDriver : MonoBehaviour
{
2025-04-01 21:12:28 +08:00
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize()
{
LastestUpdateFrame = 0;
}
#endif
2025-01-09 11:31:04 +08:00
private static int LastestUpdateFrame = 0;
void Update()
{
DebugCheckDuplicateDriver();
YooAssets.Update();
}
#if UNITY_EDITOR
void OnApplicationQuit()
{
2025-09-02 19:21:49 +08:00
// 说明在编辑器下确保播放被停止时IO类操作被终止。
YooAssets.ClearAllPackageOperation();
2025-01-09 11:31:04 +08:00
}
#endif
[Conditional("DEBUG")]
private void DebugCheckDuplicateDriver()
{
if (LastestUpdateFrame > 0)
{
if (LastestUpdateFrame == Time.frameCount)
YooLogger.Warning($"There are two {nameof(YooAssetsDriver)} in the scene. Please ensure there is always exactly one driver in the scene.");
}
LastestUpdateFrame = Time.frameCount;
}
}
}