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

Parameters

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

Returns

BuildReport A BuildReport giving build process information.

Description

构建一个播放器。

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

Parameters

levelsThe 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,例如是否运行已构建的播放器。

Returns

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

Description

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