BuildPlayer
Builds a player from a specific build profile.
阅读时间4 分钟最后更新于 4 天前
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
BuildPlayer(BuildPlayerWithProfileOptions)
Builds a player from a specific build profile.
public static BuildReport BuildPlayer(BuildPlayerWithProfileOptions buildPlayerWithProfileOptions)
Parameters
Provide various options to control the behavior of BuildPipeline.BuildPlayer when using a build profile.
Returns
Type | Description |
|---|---|
| BuildReport | A BuildReport object containing build process information. |
Examples
using UnityEditor;using UnityEditor.Build.Reporting;using UnityEditor.Build.Profile;using UnityEngine;namespace BuildDocExamples{ public class BuildPipeline_BuildPlayerWithBuildProfileExample { [MenuItem("BuildDocExamples/Build/Build iOS Demo")] public static void MyBuild() { BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>("Assets/Settings/Build Profiles/iOSDemo.asset"); BuildPlayerWithProfileOptions options = new BuildPlayerWithProfileOptions() { buildProfile = buildProfile, locationPathName = "iOSDemoBuild", options = BuildOptions.None, }; BuildReport report = BuildPipeline.BuildPlayer(options); BuildSummary summary = report.summary; // Output the build size or a failure depending on BuildPlayer. if (summary.result == BuildResult.Succeeded) { Debug.Log("Build succeeded: " + summary.totalSize + " bytes"); } if (summary.result == BuildResult.Failed) { Debug.Log("Build failed"); } } }}
BuildPlayer(EditorBuildSettingsScene[], string, BuildTarget, BuildOptions)
Builds a Player from a list of scenes.
public static BuildReport BuildPlayer(EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options)
Parameters
The scenes to include in the build. If empty, the build includes only the current open scene. Paths are relative to the project folder, for example .
Assets/MyLevels/MyScene.unityThe path to build the application to. For information on the platform extensions to include in the path, refer to Build path requirements for target platforms.
The BuildTarget to build.
Additional BuildOptions, such as whether to run the built player.
Returns
Type | Description |
|---|---|
| BuildReport | A BuildReport object containing build process information. |
Remarks
This overload is still supported, but will be replaced. Use BuildPipeline.BuildPlayer or BuildPipeline.BuildPlayer instead.
BuildPlayer(string[], string, BuildTarget, BuildOptions)
Builds a Player from a list of scene paths.
public static BuildReport BuildPlayer(string[] levels, string locationPathName, BuildTarget target, BuildOptions options)
Parameters
The scene paths to include in the build. If empty, the build includes only the current open scene. Paths are relative to the project folder, for example .
Assets/MyLevels/MyScene.unityThe path to build the application to. For information on the platform extensions to include in the path, refer to Build path requirements for target platforms.
The BuildTarget to build.
Additional BuildOptions, such as whether to run the built player.
Returns
Type | Description |
|---|---|
| BuildReport | A BuildReport object containing build process information. |
Remarks
This overload is still supported, but will be replaced. Use BuildPipeline.BuildPlayer or BuildPipeline.BuildPlayer instead.
BuildPlayer(BuildPlayerOptions)
Builds a player.
public static BuildReport BuildPlayer(BuildPlayerOptions buildPlayerOptions)
Parameters
Provide various options to control the behavior of BuildPipeline.BuildPlayer.
Returns
Type | Description |
|---|---|
| BuildReport | A BuildReport object containing build process information. |
Remarks
Use this function to programatically create a build of your project.
When working with BuildProfile, use the overload of BuildPipeline.BuildPlayer that accepts BuildPlayerWithProfileOptions instead. That overload applies the settings from the specified build profile to the build process.
Calling this method will invalidate any variables in the editor script that reference GameObjects, so they will need to be reacquired after the call.
Scripts can run at strategic points during the build by implementing one of the supported callback interfaces, for example BuildPlayerProcessor, IPreprocessBuildWithContext and IPostprocessBuildWithContext, or by overriding AssetPostprocessor.OnProcessScene(Scene, SceneImportContext).
Note: Be aware that changes to scripting symbols only take effect at the next code reload, when scripts are recompiled.
This means if you make changes to the defined scripting symbols via code using SetDefineSymbolsForGroup without a code reload before calling this function, those changes won't take effect.
It also means that the built-in scripting symbols defined for the current active target platform (such as UNITY_STANDALONE_WIN, or UNITY_ANDROID) remain in place even if you try to build for a different target platform, which can result in the wrong code being compiled into your build.
Additional Resources: BuildPlayerWindow.DefaultBuildMethods.BuildPlayer
Examples
using UnityEditor;using UnityEngine;using UnityEditor.Build.Reporting;namespace BuildDocExamples{ // Output the build size or a failure depending on BuildPlayer. public class BuildPipeline_BuildPlayerExample { [MenuItem("BuildDocExamples/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"); } } }}