Version: 2021.1
public static Build.Reporting.BuildReport BuildPlayer (BuildPlayerOptions buildPlayerOptions);

参数

buildPlayerOptions 提供各种选项以控制 BuildPipeline.BuildPlayer 的行为。

返回

BuildReport 用于提供构建过程信息的 BuildReport。

描述

构建一个播放器。

使用此函数以编程方式创建项目的构建。 请注意,在 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"); } } }

public static Build.Reporting.BuildReport BuildPlayer (string[] levels, string locationPathName, BuildTarget target, BuildOptions options);
public static Build.Reporting.BuildReport BuildPlayer (EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options);

参数

scenes 要包含在版本中的场景。如果为空,则版本只包含当前打开的场景。路径是项目文件夹的相对路径 (Assets/MyLevels/MyScene.unity)。
locationPathName 要构建应用程序的路径。
target 要构建的 BuildTarget
options 其他 BuildOptions,例如是否运行已构建的播放器。

返回

BuildReport 发生错误时显示的错误消息。

描述

构建一个播放器。这些重载仍受支持,但将被替换。请改用 BuildPlayer (BuildPlayerOptions buildPlayerOptions)。