SpriteAtlasClearTask.cs 944 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. namespace XGame.Editor.Asset.Tools
  3. {
  4. public class SpriteAtlasClearTask
  5. {
  6. public void Run()
  7. {
  8. var count = 0;
  9. try
  10. {
  11. var directories = FileUtil.GetAtlasRoots();
  12. var guids = UnityEditor.AssetDatabase.FindAssets("t:SpriteAtlas", directories);
  13. count = guids.Length;
  14. foreach (var guid in guids)
  15. {
  16. var assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
  17. UnityEditor.FileUtil.DeleteFileOrDirectory(assetPath);
  18. }
  19. }
  20. catch (Exception ex)
  21. {
  22. UnityEngine.Debug.LogException(ex);
  23. }
  24. if (count > 0)
  25. UnityEditor.AssetDatabase.Refresh();
  26. UnityEngine.Debug.Log($"清理SpriteAtlas完成,删除文件数量: {count}");
  27. }
  28. }
  29. }