using System;
using RedHotRoast;
using UnityEngine;

public static class MemoryManager
{
    private static long nextCleanTime = 600; // 每 600 秒检查一次
    private static long timeConfig;


    public static void StartMemoryMonitor(int checkInterval = 600)
    {
#if !UNITY_EDITOR
        timeConfig = checkInterval;
        SetTime();
#endif
    }

    private static void SetTime()
    {
        nextCleanTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + timeConfig * 60;
    }

    public static void CleanMemoryMonitor()
    {
        if (DateTimeOffset.UtcNow.ToUnixTimeSeconds() > nextCleanTime)
        {
            SetTime();

            Resources.UnloadUnusedAssets();

            GC.Collect(); // 强制 GC，注意可能造成短暂卡顿
            Debug.Log("[MemoryManager] 内存清理完成");
        }
    }
}