using System;

namespace XGame.Editor.Asset.Tools
{
    public class SpriteAtlasClearTask
    {
        public void Run()
        {
            var count = 0;
            try
            {
                var directories = FileUtil.GetAtlasRoots();
                var guids = UnityEditor.AssetDatabase.FindAssets("t:SpriteAtlas", directories);
                count = guids.Length;
                foreach (var guid in guids)
                {
                    var assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
                    UnityEditor.FileUtil.DeleteFileOrDirectory(assetPath);
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogException(ex);
            }
            if (count > 0)
                UnityEditor.AssetDatabase.Refresh();
            UnityEngine.Debug.Log($"清理SpriteAtlas完成，删除文件数量: {count}");
        }
    }
}
