XBuildPipeline.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using XGame.Editor.Build.AssetBundles;
  2. using XGame.Editor.Asset;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace XGame.Editor.Build
  6. {
  7. public static class XBuildPipeline
  8. {
  9. [MenuItem("Build/一键打包", priority = 1)]
  10. private static void BuildApp()
  11. {
  12. ////收集资源信息
  13. XBuildPipeline.GenerateAddressable();
  14. ////创建图集配置
  15. //CreateAtlas();
  16. ////资源打包成AB包
  17. //BuildBundles();
  18. ////拷贝资源
  19. //CopyStreamAssets();
  20. //打包App
  21. BuildAppWindow.CreateWindow();
  22. }
  23. public static void GenerateAddressable()
  24. {
  25. var buildTask = new AddressableBuildTask();
  26. buildTask.Run();
  27. //CollectCustomAddressableNames();
  28. BuildLog.Log($"GenerateAddressable finish. Time: {System.DateTime.Now}");
  29. }
  30. [MenuItem("Build/CreateAtlas", priority = 21)]
  31. public static void GenerateAtlas()
  32. {
  33. var task = new AtlasBuildTask();
  34. task.Run();
  35. }
  36. [MenuItem("Build/BuildAssetBundles", priority = 22)]
  37. public static bool BuildAssetBundles()
  38. {
  39. var builder = new BundleContextBuilder();
  40. if (!builder.Build())
  41. {
  42. return false;
  43. }
  44. var context = builder.Product;
  45. var controller = BundleManifestsController.Creat(context);
  46. var pipeline = new SbpBuildPipeline();
  47. var buildTask = new AssetBundleBuildTask(context, controller, pipeline);
  48. return buildTask.Run();
  49. }
  50. //[MenuItem("Build/SerializeConfigs", priority = 23)]
  51. private static void SerializeConfigs()
  52. {
  53. SerializableUtils.SerializeAllConfigs();
  54. }
  55. [MenuItem("Build/ExportAssets", priority = 24)]
  56. private static void ExportAssets()
  57. {
  58. var context = new BuildContext()
  59. {
  60. config = new BuildConfig()
  61. {
  62. editor = new BuildConfig.EditorSettings()
  63. {
  64. isNative = true
  65. },
  66. project = new BuildConfig.ProjectSettings()
  67. {
  68. outputPath = PathDefine.DefaultOutputPath
  69. }
  70. }
  71. };
  72. IBuildCommand cmd = new CmdExportAssets();
  73. if (cmd is IBuildContextAdapter adapter)
  74. {
  75. adapter.Context = context;
  76. }
  77. cmd.Start();
  78. }
  79. [MenuItem("Build/BuildPlayer", priority = 25)]
  80. private static void BuildPlayer()
  81. {
  82. LocalizedBuild.BuildPlayer();
  83. }
  84. [MenuItem("Build/CreatePackerManifest", priority = 46)]
  85. private static void CreatePackerManifest()
  86. {
  87. ABPackerInfoManifest.LoadOrCreate();
  88. }
  89. [MenuItem("Build/GenAssetbundleManifests", priority = 47)]
  90. public static bool GenerateBundleManifests()
  91. {
  92. var builder = new BundleContextBuilder();
  93. if (!builder.Build())
  94. {
  95. return false;
  96. }
  97. var controller = BundleManifestsController.Creat(builder.Product);
  98. return controller.GenerateManifests();
  99. }
  100. [MenuItem("Build/BuildManifestBundle", priority = 48)]
  101. public static bool BuildManifestBundle()
  102. {
  103. // sbp打包速度很快,一般不用单独打manifest的包
  104. var pipeline = new NormalBuildPipeline();
  105. var task = new ManifestBundleBuildTask(pipeline);
  106. return task.Run();
  107. }
  108. [MenuItem("Build/反序列化Manifest", priority = 101)]
  109. private static void DeserializeABManifest()
  110. {
  111. DeserializeABManifestWindow.CreateWindow();
  112. }
  113. [MenuItem("Build/重新编译代码", priority = 102)]
  114. private static void RequestScriptCompilation()
  115. {
  116. UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
  117. }
  118. [MenuItem("Build/Assetbundle分组/常规")]
  119. public static bool GenAssetbundleGroupsNormal()
  120. {
  121. var outputPath = $"{PathDefine.ExtAssetsPath}/AbGroupsNormal.json";
  122. var task = new AssetBundleGroupsTask(outputPath, AssetBundleGroupsTask.AbGroupMode.Normal);
  123. return task.Excute();
  124. }
  125. [MenuItem("Build/Assetbundle分组/依赖顺序")]
  126. public static bool GenAssetbundlesByDependencies()
  127. {
  128. var outputPath = $"{PathDefine.ExtAssetsPath}/AbGroupsByDependencies.json";
  129. var task = new AssetBundleGroupsTask(outputPath, AssetBundleGroupsTask.AbGroupMode.Dependencies);
  130. return task.Excute();
  131. }
  132. }
  133. }