|
建立一个球员的时候,你有时想用某种方式修改内置的播放器。例如,你可能想添加一个自定义图标,复制一些文件到播放器或建立一个安装程序。你可以通过编辑脚本使用这样做buildpipeline.buildplayer运行建立并遵循它任何后处理的代码,你需要:—
// JS example.
import System.Diagnostics;
class ScriptBatch {
@MenuItem("MyTools/Windows Build With Postprocess")
static function BuildGame() {
// Get filename.
var path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", "");
var levels : 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/WebPlayerTemplates/Readme.txt", path + "Readme.txt");
// Run the game (Process class from System.Diagnostics).
var proc = new Process();
proc.StartInfo.FileName = path + "BuiltGame.exe";
proc.Start();
}
}
// C# example.
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/WebPlayerTemplates/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属性
你也可以使用的postprocessorder参数postprocessbuildattribute定义你的建造方法的执行顺序,并与过程类这些方法在上一节所示你的外部脚本调用。这个参数是用来排序的建立方法,从低到高,你可以指定任何正面或负面的价值呢。
|
|