CommandBuild.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEditor.Build;
  5. #if UNITY_2018_4_OR_NEWER
  6. using UnityEditor.Build.Reporting;
  7. #endif
  8. using UnityEngine;
  9. public class CommandBuild : MonoBehaviour
  10. {
  11. private static string[] GetAllScenes()
  12. {
  13. string[] scenes = new string[] {
  14. "Assets/API-Example/HomeScene.unity",
  15. "Assets/API-Example/Examples/Basic/JoinChannelVideo/BasicVideoCallScene.unity",
  16. "Assets/API-Example/Examples/Basic/JoinChannelAudio/BasicAudioCallScene.unity",
  17. "Assets/API-Example/Examples/Advanced/AudioMixing/AudioMixingScene.unity",
  18. "Assets/API-Example/Examples/Advanced/AudioSpectrum/AudioSpectrumScene.unity",
  19. "Assets/API-Example/Examples/Advanced/ChannelMediaRelay/ChannelMediaRelayScene.unity",
  20. "Assets/API-Example/Examples/Advanced/ContentInspect/ContentInspectScene.unity",
  21. "Assets/API-Example/Examples/Advanced/CustomCaptureAudio/CustomCaptureAudioScene.unity",
  22. "Assets/API-Example/Examples/Advanced/CustomCaptureVideo/CustomCaptureVideoScene.unity",
  23. "Assets/API-Example/Examples/Advanced/CustomRenderAudio/CustomRenderAudioScene.unity",
  24. "Assets/API-Example/Examples/Advanced/DeviceManager/DeviceManagerScene.unity",
  25. "Assets/API-Example/Examples/Advanced/DualCamera/DualCameraScene.unity",
  26. "Assets/API-Example/Examples/Advanced/JoinChannelVideoToken/JoinChannelVideoTokenScene.unity",
  27. "Assets/API-Example/Examples/Advanced/JoinChannelWithUserAccount/JoinChannelWithUserAccountScene.unity",
  28. "Assets/API-Example/Examples/Advanced/MediaPlayer/MediaPlayerScene.unity",
  29. "Assets/API-Example/Examples/Advanced/MediaRecorder/MediaRecorderScene.unity",
  30. "Assets/API-Example/Examples/Advanced/Metadata/MetadataScene.unity",
  31. "Assets/API-Example/Examples/Advanced/ProcessAudioRawData/ProcessAudioRawDataScene.unity",
  32. "Assets/API-Example/Examples/Advanced/ProcessVideoRawData/ProcessVideoRawDataScene.unity",
  33. "Assets/API-Example/Examples/Advanced/PushEncodedVideoImage/PushEncodedVideoImageScene.unity",
  34. "Assets/API-Example/Examples/Advanced/RtmpStreaming/RtmpStreamingScene.unity",
  35. "Assets/API-Example/Examples/Advanced/ScreenShare/ScreenShareScene.unity",
  36. "Assets/API-Example/Examples/Advanced/ScreenShareWhileVideoCall/ScreenShareWhileVideoCallScene.unity",
  37. "Assets/API-Example/Examples/Advanced/SetBeautyEffectOptions/SetBeautyEffectOptionsScene.unity",
  38. "Assets/API-Example/Examples/Advanced/SetEncryption/SetEncryptionScene.unity",
  39. "Assets/API-Example/Examples/Advanced/SetVideoEncodeConfiguration/SetVideoEncodeConfigurationScene.unity",
  40. "Assets/API-Example/Examples/Advanced/SpatialAudioWithMediaPlayer/SpatialAudioWithMediaPlayerScene.unity",
  41. "Assets/API-Example/Examples/Advanced/StartDirectCdnStreaming/StartDirectCdnStreamingScene.unity",
  42. "Assets/API-Example/Examples/Advanced/StartLocalVideoTranscoder/StartLocalVideoTranscoderScene.unity",
  43. "Assets/API-Example/Examples/Advanced/StartRhythmPlayer/StartRhythmPlayerScene.unity",
  44. "Assets/API-Example/Examples/Advanced/StartRtmpStreamWithTranscoding/StartRtmpStreamWithTranscodingScene.unity",
  45. "Assets/API-Example/Examples/Advanced/StreamMessage/StreamMessageScene.unity",
  46. "Assets/API-Example/Examples/Advanced/TakeSnapshot/TakeSnapshotScene.unity",
  47. "Assets/API-Example/Examples/Advanced/VirtualBackground/VirtualBackgroundScene.unity",
  48. "Assets/API-Example/Examples/Advanced/VoiceChanger/VoiceChangerScene.unity"
  49. };
  50. return scenes;
  51. }
  52. [MenuItem("Build/Android")]
  53. public static void BuildAndrod()
  54. {
  55. BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
  56. buildPlayerOptions.scenes = GetAllScenes();
  57. buildPlayerOptions.locationPathName = "../Build/Android.apk";
  58. buildPlayerOptions.target = BuildTarget.Android;
  59. buildPlayerOptions.options = BuildOptions.None;
  60. #if UNITY_2018_4_OR_NEWER
  61. BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
  62. BuildSummary summary = report.summary;
  63. if (summary.result == BuildResult.Succeeded)
  64. {
  65. Debug.Log("Build Android succeeded: " + summary.totalSize + " bytes");
  66. }
  67. if (summary.result == BuildResult.Failed)
  68. {
  69. Debug.Log("Build Android failed");
  70. }
  71. #else
  72. string message = BuildPipeline.BuildPlayer(buildPlayerOptions);
  73. Debug.Log("Build Android: " + message);
  74. #endif
  75. }
  76. [MenuItem("Build/IPhone")]
  77. public static void BuildIPhone()
  78. {
  79. BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
  80. buildPlayerOptions.scenes = GetAllScenes();
  81. buildPlayerOptions.locationPathName = "../Build/IPhone";
  82. buildPlayerOptions.target = BuildTarget.iOS;
  83. buildPlayerOptions.options = BuildOptions.None;
  84. #if UNITY_2018_4_OR_NEWER
  85. BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
  86. BuildSummary summary = report.summary;
  87. if (summary.result == BuildResult.Succeeded)
  88. {
  89. Debug.Log("Build IPhone succeeded: " + summary.totalSize + " bytes");
  90. }
  91. if (summary.result == BuildResult.Failed)
  92. {
  93. Debug.Log("Build IPhone failed");
  94. }
  95. #else
  96. string message = BuildPipeline.BuildPlayer(buildPlayerOptions);
  97. Debug.Log("Build IPhone: " + message);
  98. #endif
  99. }
  100. [MenuItem("Build/Mac")]
  101. public static void BuildMac()
  102. {
  103. BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
  104. buildPlayerOptions.scenes = GetAllScenes();
  105. buildPlayerOptions.locationPathName = "../Build/Mac.app";
  106. buildPlayerOptions.target = BuildTarget.StandaloneOSX;
  107. buildPlayerOptions.options = BuildOptions.None;
  108. #if UNITY_2018_4_OR_NEWER
  109. BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
  110. BuildSummary summary = report.summary;
  111. if (summary.result == BuildResult.Succeeded)
  112. {
  113. Debug.Log("Build Mac succeeded: " + summary.totalSize + " bytes");
  114. }
  115. if (summary.result == BuildResult.Failed)
  116. {
  117. Debug.Log("Build Mac failed");
  118. }
  119. #else
  120. string message = BuildPipeline.BuildPlayer(buildPlayerOptions);
  121. Debug.Log("Build Mac: " + message);
  122. #endif
  123. }
  124. [MenuItem("Build/x86")]
  125. public static void BuildWin32()
  126. {
  127. BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
  128. buildPlayerOptions.scenes = GetAllScenes();
  129. buildPlayerOptions.locationPathName = "../Build/x86/x86.exe";
  130. buildPlayerOptions.target = BuildTarget.StandaloneWindows;
  131. buildPlayerOptions.options = BuildOptions.None;
  132. #if UNITY_2018_4_OR_NEWER
  133. BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
  134. BuildSummary summary = report.summary;
  135. if (summary.result == BuildResult.Succeeded)
  136. {
  137. Debug.Log("Build x86 succeeded: " + summary.totalSize + " bytes");
  138. }
  139. if (summary.result == BuildResult.Failed)
  140. {
  141. Debug.Log("Build x86 failed");
  142. }
  143. #else
  144. string message = BuildPipeline.BuildPlayer(buildPlayerOptions);
  145. Debug.Log("Build Win32: " + message);
  146. #endif
  147. }
  148. [MenuItem("Build/x86_64")]
  149. public static void BuildWin64()
  150. {
  151. BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
  152. buildPlayerOptions.scenes = GetAllScenes();
  153. buildPlayerOptions.locationPathName = "../Build/x86_64/x86_64.exe";
  154. buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
  155. buildPlayerOptions.options = BuildOptions.None;
  156. #if UNITY_2018_4_OR_NEWER
  157. BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
  158. BuildSummary summary = report.summary;
  159. if (summary.result == BuildResult.Succeeded)
  160. {
  161. Debug.Log("Build x86_64 succeeded: " + summary.totalSize + " bytes");
  162. }
  163. if (summary.result == BuildResult.Failed)
  164. {
  165. Debug.Log("Build x86_64 failed");
  166. }
  167. #else
  168. string message = BuildPipeline.BuildPlayer(buildPlayerOptions);
  169. Debug.Log("Build x86_64: " + message);
  170. #endif
  171. }
  172. [MenuItem("Build/All")]
  173. public static void BuildAll()
  174. {
  175. BuildAndrod();
  176. BuildIPhone();
  177. BuildMac();
  178. BuildWin32();
  179. BuildWin64();
  180. }
  181. }