BuildPlayerCommand.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using HybridCLR.Editor.Commands;
  2. using HybridCLR.Editor.Installer;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using UnityEditor;
  7. using UnityEngine;
  8. namespace HybridCLR.Editor
  9. {
  10. public class BuildPlayerCommand
  11. {
  12. public static void CopyAssets(string outputDir)
  13. {
  14. Directory.CreateDirectory(outputDir);
  15. foreach(var srcFile in Directory.GetFiles(Application.streamingAssetsPath))
  16. {
  17. string dstFile = $"{outputDir}/{Path.GetFileName(srcFile)}";
  18. File.Copy(srcFile, dstFile, true);
  19. }
  20. }
  21. public static void InstallFromRepo()
  22. {
  23. var ic = new InstallerController();
  24. ic.InstallDefaultHybridCLR();
  25. }
  26. public static void InstallBuildWin64()
  27. {
  28. InstallFromRepo();
  29. Build_Win64(true);
  30. }
  31. [MenuItem("Build/Win64")]
  32. public static void Build_Win64()
  33. {
  34. Build_Win64(false);
  35. }
  36. public static void Build_Win64(bool existWhenCompleted)
  37. {
  38. BuildTarget target = BuildTarget.StandaloneWindows64;
  39. BuildTarget activeTarget = EditorUserBuildSettings.activeBuildTarget;
  40. if (activeTarget != BuildTarget.StandaloneWindows64 && activeTarget != BuildTarget.StandaloneWindows)
  41. {
  42. Debug.LogError("请先切到Win平台再打包");
  43. return;
  44. }
  45. // Get filename.
  46. string outputPath = $"{SettingsUtil.ProjectDir}/Release-Win64";
  47. var buildOptions = BuildOptions.CompressWithLz4;
  48. string location = $"{outputPath}/HybridCLRTrial.exe";
  49. PrebuildCommand.GenerateAll();
  50. Debug.Log("====> Build App");
  51. BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
  52. {
  53. scenes = new string[] { "Assets/Scenes/main.unity" },
  54. locationPathName = location,
  55. options = buildOptions,
  56. target = target,
  57. targetGroup = BuildTargetGroup.Standalone,
  58. };
  59. var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
  60. if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
  61. {
  62. Debug.LogError("打包失败");
  63. if (existWhenCompleted)
  64. {
  65. EditorApplication.Exit(1);
  66. }
  67. return;
  68. }
  69. Debug.Log("====> 复制热更新资源和代码");
  70. BuildAssetsCommand.BuildAndCopyABAOTHotUpdateDlls();
  71. BashUtil.CopyDir(Application.streamingAssetsPath, $"{outputPath}/HybridCLRTrial_Data/StreamingAssets", true);
  72. }
  73. }
  74. }