ABPackerInfo.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.IO;
  3. using UnityEditor;
  4. namespace XGame.Editor.Build.AssetBundles
  5. {
  6. [Serializable]
  7. public class ABPackerInfo : IComparable
  8. {
  9. [UnityEngine.SerializeField]
  10. private long packerId;
  11. public ABPackerType packerType;
  12. public string GUID;
  13. public string AssetPath
  14. {
  15. get
  16. {
  17. if (string.IsNullOrEmpty(GUID))
  18. {
  19. return string.Empty;
  20. }
  21. return AssetDatabase.GUIDToAssetPath(GUID);
  22. }
  23. }
  24. public bool IsDirectory => Directory.Exists(AssetPath);
  25. public bool IsFile => File.Exists(AssetPath);
  26. public long PackerId => packerId;
  27. public ABPackerInfo()
  28. {
  29. packerId = System.DateTime.Now.Ticks;
  30. }
  31. public override string ToString()
  32. {
  33. return $"PackerInfo GUID:{GUID} Type:{packerType} Path:{AssetPath}";
  34. }
  35. public int CompareTo(object obj)
  36. {
  37. var compare = obj as ABPackerInfo;
  38. if (compare == null) return -1;
  39. var result = packerType - compare.packerType;
  40. if (result == 0)
  41. {
  42. if (packerType == ABPackerType.SingleAsset)
  43. {
  44. //资源在前,文件夹在后
  45. int sign_0 = this.IsFile ? 0 : 1;
  46. int sign_1 = compare.IsFile ? 0 : 1;
  47. result = sign_0 - sign_1;
  48. if (result == 0)
  49. {
  50. result = string.Compare(AssetPath, compare.AssetPath, StringComparison.OrdinalIgnoreCase);
  51. }
  52. }
  53. else
  54. {
  55. // 子文件夹在前,父文件夹在后
  56. var path_0 = AssetPath;
  57. var path_1 = compare.AssetPath;
  58. if (path_0.Contains(path_1))
  59. {
  60. result = -1;
  61. }
  62. else if (path_1.Contains(path_0))
  63. {
  64. result = 1;
  65. }
  66. else
  67. {
  68. result = string.Compare(path_0, path_1, StringComparison.OrdinalIgnoreCase);
  69. }
  70. }
  71. }
  72. return result;
  73. }
  74. }
  75. }