LoaderBuilder.Editor.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if UNITY_EDITOR
  2. using XGame.Framework.Utils;
  3. using XGame.Framework.Asset.Addressable;
  4. using UnityEngine;
  5. namespace XGame.Framework.Asset
  6. {
  7. internal partial class LoaderBuilder
  8. {
  9. private void InitMainBundleEditor()
  10. {
  11. _isBundleEncrypt = false;
  12. var bundlePath = FileUtils.GetAssetBundlePath(Define.MANIFEST_BUNDLE_FULLNAME);
  13. _mainbundle = AssetBundle.LoadFromFile(bundlePath);//"kcmanifest.bundle"
  14. if (_mainbundle == null)
  15. { //Editor下多尝试一次加载
  16. AssetsLog.Debug($"加载未加密Manifest Assetbundle失败,更换为加密方式加载。");
  17. _mainbundle = AssetBundle.LoadFromFile(bundlePath, 0, Define.MANIFEST_BUNDLE_OFFSET);
  18. if (_mainbundle != null)
  19. {
  20. _isBundleEncrypt = true;
  21. }
  22. else
  23. {
  24. Log.Error($"Manifest Assetbundle加载失败!");
  25. }
  26. }
  27. }
  28. private IAddressableManifest LoadAddressableManifestEditor()
  29. {
  30. var manifest = new CSharpAddressableManifest();
  31. var infoSo = LoadAddressableInfosSo(AddressableClassify.BuiltIn);
  32. manifest.Init(infoSo);
  33. infoSo = LoadAddressableInfosSo(AddressableClassify.Product);
  34. manifest.Init(infoSo);
  35. infoSo = LoadAddressableInfosSo(AddressableClassify.Tests);
  36. manifest.Init(infoSo);
  37. return manifest;
  38. }
  39. private AddressableInfosSo LoadAddressableInfosSo(AddressableClassify classify)
  40. {
  41. string fileName;// = classify == AddressableClassifyOperation.BuiltIn ? Define.BUILTIN_ASSET_MANIFEST : Define.PRODUCT_ASSET_MANIFEST;
  42. if (classify == AddressableClassify.BuiltIn)
  43. {
  44. fileName = Define.BUILTIN_ASSET_MANIFEST;
  45. }
  46. else if (classify == AddressableClassify.Tests)
  47. {
  48. fileName = "TestAssetsManifest";
  49. }
  50. else
  51. {
  52. fileName = Define.PRODUCT_ASSET_MANIFEST;
  53. }
  54. var manifestPath = $"Assets/AssetConfigs/Addressable/{fileName}.asset";
  55. var assetManifest = UnityEditor.AssetDatabase.LoadAssetAtPath<AddressableInfosSo>(manifestPath);
  56. if (assetManifest == null && classify == AddressableClassify.Product)
  57. {
  58. Log.Error($"Can't find AddressableInfosSo. Path:{manifestPath}");
  59. }
  60. return assetManifest;
  61. }
  62. }
  63. }
  64. #endif