PackageBundle.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Linq;
  3. namespace YooAsset
  4. {
  5. [Serializable]
  6. internal class PackageBundle
  7. {
  8. /// <summary>
  9. /// 资源包名称
  10. /// </summary>
  11. public string BundleName;
  12. /// <summary>
  13. /// Unity引擎生成的CRC
  14. /// </summary>
  15. public uint UnityCRC;
  16. /// <summary>
  17. /// 文件哈希值
  18. /// </summary>
  19. public string FileHash;
  20. /// <summary>
  21. /// 文件校验码
  22. /// </summary>
  23. public string FileCRC;
  24. /// <summary>
  25. /// 文件大小(字节数)
  26. /// </summary>
  27. public long FileSize;
  28. /// <summary>
  29. /// 文件是否加密
  30. /// </summary>
  31. public bool Encrypted;
  32. /// <summary>
  33. /// 资源包的分类标签
  34. /// </summary>
  35. public string[] Tags;
  36. /// <summary>
  37. /// 依赖的资源包ID集合
  38. /// </summary>
  39. public int[] DependIDs;
  40. /// <summary>
  41. /// 所属的包裹名称
  42. /// </summary>
  43. public string PackageName { private set; get; }
  44. /// <summary>
  45. /// 所属的构建管线
  46. /// </summary>
  47. public string Buildpipeline { private set; get; }
  48. /// <summary>
  49. /// 缓存GUID
  50. /// </summary>
  51. public string CacheGUID
  52. {
  53. get { return FileHash; }
  54. }
  55. /// <summary>
  56. /// 文件名称
  57. /// </summary>
  58. private string _fileName;
  59. public string FileName
  60. {
  61. get
  62. {
  63. if (string.IsNullOrEmpty(_fileName))
  64. throw new Exception("Should never get here !");
  65. return _fileName;
  66. }
  67. }
  68. /// <summary>
  69. /// 文件后缀名
  70. /// </summary>
  71. private string _fileExtension;
  72. public string FileExtension
  73. {
  74. get
  75. {
  76. if (string.IsNullOrEmpty(_fileExtension))
  77. throw new Exception("Should never get here !");
  78. return _fileExtension;
  79. }
  80. }
  81. public PackageBundle()
  82. {
  83. }
  84. /// <summary>
  85. /// 解析资源包
  86. /// </summary>
  87. public void ParseBundle(PackageManifest manifest)
  88. {
  89. PackageName = manifest.PackageName;
  90. Buildpipeline = manifest.BuildPipeline;
  91. _fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName);
  92. _fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
  93. }
  94. /// <summary>
  95. /// 是否包含Tag
  96. /// </summary>
  97. public bool HasTag(string[] tags)
  98. {
  99. if (tags == null || tags.Length == 0)
  100. return false;
  101. if (Tags == null || Tags.Length == 0)
  102. return false;
  103. foreach (var tag in tags)
  104. {
  105. if (Tags.Contains(tag))
  106. return true;
  107. }
  108. return false;
  109. }
  110. /// <summary>
  111. /// 是否包含任意Tags
  112. /// </summary>
  113. public bool HasAnyTags()
  114. {
  115. if (Tags != null && Tags.Length > 0)
  116. return true;
  117. else
  118. return false;
  119. }
  120. /// <summary>
  121. /// 检测资源包文件内容是否相同
  122. /// </summary>
  123. public bool Equals(PackageBundle otherBundle)
  124. {
  125. if (FileHash == otherBundle.FileHash)
  126. return true;
  127. return false;
  128. }
  129. }
  130. }