buildPlayerOptions | 提供各种选项以控制 BuildPipeline.BuildPlayer 的行为。 |
BuildReport A BuildReport giving build process information.
构建一个播放器。
使用此函数以编程方式创建项目的构建。 请注意,在 BuildPlayer 调用/之前/在编辑器脚本中获取的对 GameObject 的任何引用都将在该调用后无效,并且需要重新获取。
using UnityEditor; using UnityEngine; using UnityEditor.Build.Reporting;
// Output the build size or a failure depending on BuildPlayer.
public class BuildPlayerExample : MonoBehaviour { [MenuItem("Build/Build iOS")] public static void MyBuild() { BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity", "Assets/Scene2.unity" }; buildPlayerOptions.locationPathName = "iOSBuild"; buildPlayerOptions.target = BuildTarget.iOS; buildPlayerOptions.options = BuildOptions.None;
BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions); BuildSummary summary = report.summary;
if (summary.result == BuildResult.Succeeded) { Debug.Log("Build succeeded: " + summary.totalSize + " bytes"); }
if (summary.result == BuildResult.Failed) { Debug.Log("Build failed"); } } }
levels | The Scenes to be included in the build. If empty, the currently open Scene will be built. Paths are relative to the project folder (Assets/MyLevels/MyScene.unity). |
locationPathName | 要构建应用程序的路径。 |
target | 要构建的 BuildTarget。 |
options | 其他 BuildOptions,例如是否运行已构建的播放器。 |
BuildReport 发生错误时显示的错误消息。
构建一个播放器。这些重载仍受支持,但将被替换。请改用 BuildPlayer (BuildPlayerOptions buildPlayerOptions)。