AssetBundleManifestExt.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using XGame.Framework.Asset;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. namespace XGame.Editor.Build.AssetBundles
  6. {
  7. public static class AssetBundleManifestExt
  8. {
  9. /// <summary>
  10. /// 编辑器扩展方法
  11. /// 返回所有bundle的FullName
  12. /// </summary>
  13. /// <param name="manifest"></param>
  14. /// <returns></returns>
  15. public static string[] GetAllBundleNames(this IAssetBundleManifest manifest)
  16. {
  17. if (manifest is CSharpAssetBundleManifest csBundleManifest)
  18. {
  19. var fileInfo = csBundleManifest.GetType().GetField("_bundleIdToNameMap", BindingFlags.NonPublic | BindingFlags.Instance);
  20. if (fileInfo != null)
  21. {
  22. var bundles = (Dictionary<uint, string>)fileInfo.GetValue(csBundleManifest);
  23. return bundles.Values.ToArray();
  24. }
  25. }
  26. return null;
  27. }
  28. /// <summary>
  29. /// 编辑器扩展方法
  30. /// 返回所有的bundleInfo
  31. /// </summary>
  32. /// <param name="manifest"></param>
  33. /// <returns></returns>
  34. public static AssetBundleInfo[] GetAllBundleInfos(this IAssetBundleManifest manifest)
  35. {
  36. if (manifest is CSharpAssetBundleManifest csBundleManifest)
  37. {
  38. var fileInfo = csBundleManifest.GetType().GetField("_bundleInfoMap", BindingFlags.NonPublic | BindingFlags.Instance);
  39. if (fileInfo != null)
  40. {
  41. var bundles = (Dictionary<string, AssetBundleInfo>)fileInfo.GetValue(csBundleManifest);
  42. return bundles.Values.ToArray();
  43. }
  44. }
  45. return null;
  46. }
  47. }
  48. }