플레이어를 빌드할 때는 빌드된 플레이어를 어떤 방식으로든 수정해야 할 때도 있습니다. 예를 들어 커스텀 아이콘을 추가하거나, 플레이어 옆에 문서를 복사하거나 설치 프로그램을 빌드하려고 할 수 있습니다. BuildPipeline.BuildPlayer를 사용하여 에디터 스크립팅을 통해 빌드를 실행한 후 필요한 포스트 프로세싱 코드로 이어서 작업할 수 있습니다.
// 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/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();
}
}
PostProcessBuildAttribute의 postprocessOrder 파라미터를 사용하여 빌드 메서드의 실행 순서를 정의하고, 마지막 섹션에 나와 있는 것처럼 이 메서드에서 Process 클래스를 사용하여 외부 스크립트를 호출할 수도 있습니다. 이 파라미터는 빌드 메서드를 낮음에서 높음으로 정렬하는 데 사용되며, 음수 또는 양수 값을 할당할 수 있습니다.