6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity 2018.1からBuildPipeline APIは、文字列じゃなくてBuildReportっていうオブジェクトを返すようになった

Last updated at Posted at 2018-12-24

Unity 2018.1からBuildPipeline APIは、文字列じゃなくてBuildReportっていうオブジェクトを返すようになりました。

Unity 公式の「Upgrading to Unity 2018.1」にも載っている変更内容。

BuildPipeline.BuildPlayerとかBuildPipeline.BuildAssetBundlesみたいなBuildPipeline系のAPI。

Unity 2017.4まではこれらのメソッドは文字列を返していました。で、この返り値が空だったら結果は成功。空じゃなかったら失敗でエラーメッセージが返ってきました。

で、こららのAPIがUnity 2018.1で改善されて、BuildReportっていうオブジェクトを返すようになりました。この中にビルドにまつわるいろいろな情報が入っています。

これは破壊的な変更なので、Unity 2017.4(LTS)などからアップデートする際は、これが原因でコンパイルエラーになることも多いと思います。

単純に成功か失敗した、キャンセルされたかで分岐したい場合はこんな感じで書けばいいです。

var report = BuildPipeline.BuildPlayer(...);

if (report.summary.result == BuildResult.Succeeded)
{
    Debug.Log("Succeeded!");
} else if (report.summary.result == BuildResult.Failed){
    Debug.Log("Failed!");
} else if (report.summary.result == BuildResult.Cancelled) {
    Debug.Log("Cancelled!");
} else { // Unknown
    Debug.Log("Unknown!");
}

BuildReportクラスは、UnityEditor.Build.Reportingという名前空間に属し、次のようなメンバを持っています。

  • BuildFile[]型のfiles、出力結果のファイル群を司る
    • BuildFile型には、path、role、size
    • roleはUnityEditor.Build.CommonRolesに定義されている定数が使われる
  • BuildStep[]型のsteps
  • StrippingInfo型のstrippingInfo
  • BuildSummary型のsummary、まとめ情報が入っている。一例をあげると
    • 開始時刻を司るbuildStartedAt
    • 終了時刻を司るbuildEndedAt
    • 出力結果のパスを司るoutputPath
    • 成否・キャンセルを司るBuildResult
      • BuildResultはenumで次の要素をもつ
        • Unknown
        • Succeeded
        • Failed
        • Cancelled
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?