LocalizedBuild.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using XGame.Editor.Asset;
  2. using System.Diagnostics;
  3. using UnityEditor;
  4. namespace XGame.Editor.Build
  5. {
  6. internal class LocalizedBuild
  7. {
  8. /// <summary>
  9. /// 只打包apk,不做其他事
  10. /// </summary>
  11. internal static void BuildPlayer()
  12. {
  13. var buildTarget = EditorUserBuildSettings.activeBuildTarget;
  14. var outputPath = PathDefine.DefaultOutputPath;
  15. var config = new BuildConfig()
  16. {
  17. target = buildTarget,
  18. callback = BuildUtils.CallbackToString(BuildCallback),
  19. };
  20. config.project = new BuildConfig.ProjectSettings()
  21. {
  22. bundleVersion = PlayerSettings.bundleVersion,
  23. productName = PlayerSettings.productName,
  24. outputPath = outputPath,
  25. };
  26. config.android.exportAsGoogleAndroidProject = EditorUserBuildSettings.exportAsGoogleAndroidProject;
  27. config.editor.autoExplorer = buildTarget != BuildTarget.iOS;
  28. BuildPlayer(config);
  29. }
  30. internal static void BuildPlayer(BuildConfig config)
  31. {
  32. var builder = new ContextBuilder(config, false);
  33. if (builder.Build())
  34. {
  35. var context = builder.GetProduct();
  36. BuildLog.Log($"LocalizedBuild BuildPlayer begin.");
  37. //开始计时
  38. Stopwatch stopwatch = new Stopwatch();
  39. stopwatch.Start();
  40. //执行命令
  41. IBuildCommand cmd = new CmdBuildPlayer();
  42. if (cmd is IBuildContextAdapter adapter)
  43. {
  44. adapter.Context = context;
  45. }
  46. cmd.Start();
  47. //结束
  48. stopwatch.Stop();
  49. BuildLog.Log($"LocalizedBuild BuildPlayer Completed. Esapsed Time: {stopwatch.ElapsedMilliseconds} ms.");
  50. }
  51. }
  52. private static void BuildCallback(int code)
  53. {
  54. BuildLog.Log($"LocalizedBuild BuildCallback code:{code}");
  55. }
  56. }
  57. }