Last active
December 3, 2018 10:47
-
-
Save tsubaki/133d3f38f2a58123a29e33889a02fc4f to your computer and use it in GitHub Desktop.
ScriptableBuildPipeline Build Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
using UnityEditor.Build.Pipeline.Interfaces; | |
using UnityEditor.Build.Pipeline; | |
using UnityEditor.Build.Pipeline.Injector; | |
using UnityEngine.Assertions; | |
public static class BuildTest | |
{ | |
// ビルド処理 | |
[MenuItem("Build/test build")] | |
static void Build() | |
{ | |
// コンテキストを登録 | |
// ここで登録したコンテキストはTaskで使用される | |
BuildContext buildContext = new BuildContext(); | |
buildContext.SetContextObject<IMyContextData>(new MyContextData{ message = "hoge"}); | |
// タスクの登録 | |
// タスクが使用するパラメーターはコンテキストから取得する。 | |
// タスクの登録順=タスクの実行順 | |
IList<IBuildTask> taskList = new List<IBuildTask>(); | |
taskList.Add(new DisplayNameTask()); | |
// 実際に処理を実行 | |
var result = BuildTasksRunner.Run(taskList, buildContext); | |
Assert.AreEqual(ReturnCode.Success, result); | |
} | |
} | |
// BuildTasksRunnerに登録するタスク | |
class DisplayNameTask : IBuildTask | |
{ | |
// 一致するインターフェースのコンテキストを注入 | |
// ContextUsage.In:BuildContextから登録したものを使用する | |
// ContextUsage.Out:Run内で作ったコンテキストを登録 | |
[InjectContext(ContextUsage.In)] | |
IMyContextData data = null; | |
public int Version { get { return 1; } } | |
public ReturnCode Run() | |
{ | |
// 文字を表示するだけのタスク | |
// 実際にはオブジェクトの収集やコンテキストの更新・生成を行う | |
Debug.Log(data.Name); | |
return ReturnCode.Success; | |
} | |
} | |
// 今回使用する文字データのインターフェース | |
// DisplayNameTaskにInjectContextされる | |
public interface IMyContextData : IContextObject | |
{ | |
string Name { get; } | |
} | |
// コンテキストデータの実体 | |
public class MyContextData : IMyContextData | |
{ | |
public string message = null; | |
public string Name => message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment