NormalBuildPipeline.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using XGame.Editor.Asset;
  2. using System;
  3. using System.IO;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace XGame.Editor.Build.AssetBundles
  7. {
  8. public class NormalBuildPipeline : IBuildPipeline
  9. {
  10. public bool BuildAssetBundles(UnityEditor.AssetBundleBuild[] builds)
  11. {
  12. var outputPath = PathDefine.AssetBundleOutputPath; // KFADF.FileUtil.WorkPath + "/AssetBundles";
  13. if (!Directory.Exists(outputPath))
  14. {
  15. Directory.CreateDirectory(outputPath);
  16. }
  17. //LZ4压缩 | 报错中断
  18. //剔除文件头的Unity版本号信息 BuildAssetBundleOptions.AssetBundleStripUnityVersion
  19. var bundleOptions = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.StrictMode;
  20. // bool shouldCheckODR = EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS;
  21. //#if UNITY_TVOS
  22. // shouldCheckODR |= EditorUserBuildSettings.activeBuildTarget == BuildTarget.tvOS;
  23. //#endif
  24. // if (shouldCheckODR)
  25. // {
  26. //#if ENABLE_IOS_ON_DEMAND_RESOURCES
  27. // if (PlayerSettings.iOS.useOnDemandResources)
  28. // bundleOptions |= BuildAssetBundleOptions.UncompressedAssetBundle;
  29. //#endif
  30. //#if ENABLE_IOS_APP_SLICING
  31. // bundleOptions |= BuildAssetBundleOptions.UncompressedAssetBundle;
  32. //#endif
  33. // }
  34. return BuildAssetBundles(outputPath, builds, bundleOptions, EditorUserBuildSettings.activeBuildTarget);
  35. }
  36. public bool BuildAssetBundles(string outputPath, UnityEditor.AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
  37. {
  38. var manifest = BuildPipeline.BuildAssetBundles(outputPath, builds, assetBundleOptions, targetPlatform);
  39. if (manifest != null)
  40. {
  41. BuildLog.Log($"BuildAssetBundles success. Time: {DateTime.Now}");
  42. return true;
  43. }
  44. else
  45. {
  46. BuildLog.Error($"BuildAssetBundles failed. Time: {DateTime.Now}");
  47. }
  48. return false;
  49. }
  50. }
  51. }