スクリプティングをとおしたソース アセットの修正
ファイル サイズの削減

ビルド プレイヤー パイプライン

プレイヤーをビルドするとき,ビルドされたプレイヤーを何らか修正したい場合があります。例えばカスタムアイコンの追加,プレイヤーの隣にドキュメントをコピーしたり,またはインストーラを構築する,などあるかもしれません。これらはエディタースクリプトの BuildPipeline.BuildPlayer を使用し,ビルドを走らせ,ビルド後に必要な処理をコードで記述することが出来ます:

// JS example.

import System.Diagnostics;

class ScriptBatch extends MonoBehaviour {
    @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 : MonoBehaviour 
{
    [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属性

PostProcessBuildAttributeのpostprocessOrderパラメーターによってビルドメソッドの実行順を定義し,最後のメソッドでProcessクラスによって外部スクリプトを呼び出すことが可能です。このパラメーターは昇順でソートされ,使用します。そして負,または正の値を設定することが出来ます。

スクリプティングをとおしたソース アセットの修正
ファイル サイズの削減