1
0

ProjectViewGui.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Asset_Cleaner {
  4. static class ProjectViewGui {
  5. static CleanerStyleAsset.Style _style = Globals<WindowData>.Value.Style;
  6. public static void OnProjectWindowItemOnGui(string guid, Rect rect) {
  7. if (!Globals<Config>.Value.MarkRed) return;
  8. var store = Globals<BacklinkStore>.Value;
  9. if (!store.Initialized) return;
  10. var path = AssetDatabase.GUIDToAssetPath(guid);
  11. ShowRowQuantity(rect, path, store);
  12. long size = 0;
  13. var _ = store.UnusedFiles.TryGetValue(path, out size) || store.UnusedScenes.TryGetValue(path, out size);
  14. if (SearchUtils.IsUnused(path)) {
  15. var buf = GUI.color;
  16. {
  17. GUI.color = _style.RedHighlight;
  18. GUI.Box(rect, string.Empty);
  19. }
  20. GUI.color = buf;
  21. GUI.Label(rect, CommonUtils.BytesToString(size), _style.ProjectViewCounterLabel);
  22. }
  23. }
  24. static void ShowRowQuantity(Rect rect, string path, BacklinkStore backlinkStore) {
  25. if (!AssetDatabase.IsValidFolder(path))
  26. return;
  27. backlinkStore.FoldersWithQty.TryGetValue(path, out var folderWithQty);
  28. var cntFiles = folderWithQty?.UnusedFilesQty ?? 0;
  29. var cntScenes = folderWithQty?.UnusedScenesQty ?? 0;
  30. long size = folderWithQty?.UnusedSize ?? 0;
  31. if (cntFiles == 0 && cntScenes == 0) return;
  32. var countStr = cntFiles + cntScenes > 0 ? $"{cntFiles} | {cntScenes} ({CommonUtils.BytesToString(size)})" : "";
  33. GUI.Label(rect, countStr, _style.ProjectViewCounterLabel);
  34. }
  35. }
  36. }