buildPlayerOptions | 提供各种选项以控制 BuildPipeline.BuildPlayer 的行为。 |
BuildReport 用于提供构建过程信息的 BuildReport。
构建一个播放器。
Use this function to programatically create a build of your project.
Calling this method will invalidate any variables in the editor script that reference GameObjects, so they will need to be reacquired after the call.
Note: Be aware that changes to scripting symbols only take effect at the next domain reload, when scripts are recompiled.
This means if you make changes to the defined scripting symbols via code using PlayerSettings.SetDefineSymbolsForGroup without a domain 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.
See Also: BuildPlayerWindow.DefaultBuildMethods.BuildPlayer.
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"); } } }
scenes | 要包含在版本中的场景。如果为空,则版本只包含当前打开的场景。路径是项目文件夹的相对路径 (Assets/MyLevels/MyScene.unity)。 |
locationPathName | 要构建应用程序的路径。 |
target | 要构建的 BuildTarget。 |
options | 其他 BuildOptions,例如是否运行已构建的播放器。 |
BuildReport 发生错误时显示的错误消息。
构建一个播放器。这些重载仍受支持,但将被替换。请改用 BuildPlayer (BuildPlayerOptions buildPlayerOptions)。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.