ABPackerInfoManifest.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace XGame.Editor.Build.AssetBundles
  5. {
  6. public partial class ABPackerInfoManifest : ScriptableObject
  7. {
  8. public AssetBundleNameMode bundleNameMode;
  9. /// <summary>
  10. /// 是否合并shader
  11. /// 将*.shadervariants文件和其所依赖的shader一起打在一个包内
  12. /// </summary>
  13. public bool isMergeShader;
  14. [SerializeField]
  15. private List<ABPackerInfo> packerInfos;
  16. public List<ABPackerInfo> PackerInfos
  17. {
  18. get
  19. {
  20. if (packerInfos == null)
  21. {
  22. packerInfos = new List<ABPackerInfo>();
  23. }
  24. return packerInfos;
  25. }
  26. }
  27. public bool AddPackerInfo(ABPackerInfo info)
  28. {
  29. if (packerInfos == null)
  30. {
  31. packerInfos = new List<ABPackerInfo>();
  32. }
  33. int index = packerInfos.FindIndex((item => item.GUID.Equals(info.GUID)));
  34. if (index < 0)
  35. {
  36. packerInfos.Add(info);
  37. return true;
  38. }
  39. else
  40. {
  41. Debug.LogError($"Add PackerInfo. but it's repeat. {info}");
  42. }
  43. return false;
  44. }
  45. public bool IsContainGUID(string guid)
  46. {
  47. if (!string.IsNullOrEmpty(guid))
  48. {
  49. var index = packerInfos?.FindIndex((info) => info.GUID.Equals(guid)) ?? -1;
  50. if (index != -1)
  51. {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. public bool IsContainAssetPath(string assetPath)
  58. {
  59. var guid = AssetDatabase.AssetPathToGUID(assetPath);
  60. return IsContainGUID(guid);
  61. }
  62. public bool TryGetPackerInfoByGUID(string guid, out ABPackerInfo packerInfo)
  63. {
  64. if (!string.IsNullOrEmpty(guid))
  65. {
  66. var index = packerInfos?.FindIndex((info) => info.GUID.Equals(guid)) ?? -1;
  67. if (index != -1)
  68. {
  69. packerInfo = packerInfos[index];
  70. return true;
  71. }
  72. }
  73. packerInfo = default;
  74. return false;
  75. }
  76. public bool TryGetPackerInfoByAssetPath(string assetPath, out ABPackerInfo packerInfo)
  77. {
  78. return TryGetPackerInfoByGUID(AssetDatabase.AssetPathToGUID(assetPath), out packerInfo);
  79. }
  80. public bool VerifyInfoRepeat()
  81. {
  82. var listGUID = new List<string>();
  83. bool result = true;
  84. if (packerInfos != null)
  85. {
  86. foreach (var info in packerInfos)
  87. {
  88. if (listGUID.Contains(info.GUID))
  89. {
  90. Debug.LogError($"PackerInfo repeat. {info}");
  91. result = false;
  92. continue;
  93. }
  94. listGUID.Add(info.GUID);
  95. }
  96. }
  97. listGUID.Clear();
  98. return result;
  99. }
  100. public void Save()
  101. {
  102. EditorUtility.SetDirty(this);
  103. AssetDatabase.SaveAssets();
  104. AssetDatabase.Refresh();
  105. }
  106. }
  107. }