AssetBundleInfo.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 
  2. using XGame.Framework.Serialization;
  3. namespace XGame.Framework.Asset
  4. {
  5. [System.Serializable]
  6. public class AssetBundleInfo : ISerializable
  7. {
  8. /// <summary>
  9. /// bundleName,等于originBundleName或者bundleId
  10. /// </summary>
  11. public string bundleName;
  12. public string variantName;
  13. public string originBundleName;
  14. public uint bundleId;
  15. //public string[] assetPaths;
  16. public string[] assets;
  17. /// <summary>
  18. /// 依赖的bundle列表
  19. /// </summary>
  20. public uint[] dependencies;
  21. /// <summary>
  22. /// bundle的偏移值
  23. /// </summary>
  24. public uint offset;
  25. public string FullName
  26. {
  27. get
  28. {
  29. if (string.IsNullOrEmpty(bundleName))
  30. {
  31. return string.Empty;
  32. }
  33. return string.IsNullOrEmpty(variantName) ? bundleName : $"{bundleName}.{variantName}";
  34. }
  35. }
  36. public int AssetsCount => assets?.Length ?? 0;
  37. public int DependenciesCount => dependencies?.Length ?? 0;
  38. public bool ContainsAsset(string assetName)
  39. {
  40. if (assets == null || string.IsNullOrEmpty(assetName))
  41. return false;
  42. var index = System.Array.FindIndex(assets, assetName.Equals);
  43. return index >= 0;
  44. }
  45. //public int CompareTo(object obj)
  46. //{
  47. // if (obj is AssetBundleInfo compareInfo)
  48. // {
  49. // //多语言的bundle排前面
  50. // var idx_0 = originBundleName.Contains("/") ? -1 : 1;
  51. // var idx_1 = compareInfo.originBundleName.Contains("/") ? -1 : 1;
  52. // var remain = idx_0 - idx_1;
  53. // if (remain != 0)
  54. // {
  55. // return remain;
  56. // }
  57. // //ResStatic的bundle排最后
  58. // //idx_0 = originBundleName.Contains("/res/static/") ? 1 : -1;
  59. // //idx_1 = compareInfo.originBundleName.StartsWith("/res/static/") ? 1 : -1;
  60. // //remain = idx_0 - idx_1;
  61. // //if (remain != 0)
  62. // //{
  63. // // return remain;
  64. // //}
  65. // return string.CompareOrdinal(originBundleName, compareInfo.originBundleName);
  66. // }
  67. // return -1;
  68. //}
  69. void ISerializable.Serialize(IWriter writer)
  70. {
  71. writer.Write(bundleName);
  72. writer.Write(variantName);
  73. writer.Write(bundleId);
  74. writer.Write(assets);
  75. writer.Write(dependencies);
  76. writer.Write(offset);
  77. }
  78. void ISerializable.Deserialize(IReader reader)
  79. {
  80. bundleName = reader.ReadString();
  81. variantName = reader.ReadString();
  82. bundleId = reader.ReadUInt();
  83. assets = reader.ReadEnumerable<string[]>();
  84. dependencies = reader.ReadEnumerable<uint[]>();
  85. offset = reader.ReadUInt();
  86. }
  87. }
  88. }