Version: 6000.3
语言: 中文
在构建中包含其他文件
增量生成管道

自定义播放器

在构建播放器时,有时需要以某种方式修改构建的播放器。例如,您可能想要添加自定义图标、在播放器旁边复制一些文档或构建安装程序。你可以使用 BuildPipeline.BuildPlayer 通过编辑器脚本来运行构建,然后使用你需要的任何后处理代码来完成此作:

using UnityEditor;
using System.Diagnostics;

public class ScriptBatch 
{
    [MenuItem("MyTools/Windows Build With Postprocess")]
    public static void BuildGame ()
    {
        // Get filename.
        string path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", "");
        string[] levels = new string[] {"Assets/Scene1.unity", "Assets/Scene2.unity"};

        // Build player.
        BuildPipeline.BuildPlayer(levels, path + "/BuiltGame.exe", BuildTarget.StandaloneWindows, BuildOptions.None);

        // Copy a file from the project folder to the build folder, alongside the built game.
        FileUtil.CopyFileOrDirectory("Assets/Templates/Readme.txt", path + "Readme.txt");

        // Run the game (Process class from System.Diagnostics).
        Process proc = new Process();
        proc.StartInfo.FileName = path + "/BuiltGame.exe";
        proc.Start();
    }
}

PostProcessBuild属性

您还可以使用 PostProcessBuildAttribute 的 postprocessOrder 参数来定义构建方法的执行顺序,并调用脚本一段代码,允许您创建自己的组件、触发游戏事件、随时间修改组件属性以及以您喜欢的任何方式响应用户输入。更多信息
请参阅术语表
使用这些方法中的 Process 类,如上一节所示。此参数用于将构建方法从低到高排序,您可以为其分配任何负值或正值。

在构建中包含其他文件
增量生成管道