ドキュメント

サポート

ランタイム中に Build Automation のビルドマニフェストを使用

Access build manifest data at runtime for analytics and bug reporting in Unity Build Automation.
読み終わるまでの所要時間 2 分最終更新 1ヶ月前

ゲームのランタイムコードが、ビルド自体に関する主要な情報を把握していると、多くの場合に役立ちます。ビルドの名前や番号などの情報は、バグの報告や分析情報の追跡に非常に役立ちます。これを支援するために、Build Automation ではビルド時にゲームにマニフェストを挿入し、後のランタイム時にこの主要データにアクセスできるようにします。 Build Automation は、マニフェストを JSON 形式の
TextAsset
として提供します。Build Automation は、
Resources.Load()
からアクセスできるゲームリソースとしてマニフェストを保存します。ビルドマニフェストには以下の値が含まれます。

プロパティ

scmCommitId
ビルドされたコミットまたは変更リスト。
scmBranch
ビルドされたブランチの名前。
buildNumber
このビルドに対応する Build Automation ビルド番号。
buildStartTime
ビルドプロセスが開始されたときの UTC タイムスタンプ。
projectId
Unity プロジェクト ID。
bundleId
Build Automation で構成された
bundleIdentifier
(iOS と Android のみ)。
unityVersion
Build Automation がビルドの作成に使用した Unity のバージョン。
xcodeVersion
プロジェクトのビルドに使用された XCode のバージョン (iOS のみ)。
cloudBuildTargetName
ビルドされたビルドターゲットの名前。
UnityCloudBuildManifest.json というマニフェスト TextAsset が
Assets/UnityCloud/Resources
フォルダーに書き込まれます。

ローカルテスト用

ビルドマニフェスト機能をローカルでテストするには、ファイルに
UnityCloudBuildManifest.json.txt
という名前を付けます。コードリポジトリ内のプロジェクトの アセット/UnityCloud/リソース フォルダーにこのファイルをコミットしないでください。Build Automation マニフェストファイルの妨げになる可能性があるためです。

マニフェストの使用

ランタイムにマニフェストにアクセスするには、以下を使用します。

JSON 形式のビルドマニフェスト

Build Automation マニフェストにはランタイムに JSON 形式としてアクセスできます。このアセットには、カスタム解析ロジックまたはサードパーティ製の JSON パーサーを使用する必要があります。 以下の C# コード例は、GitHub Gist で MiniJSON パーサーを使用してビルドマニフェストをロードし、解析する方法を示します。
using UnityEngine;using System.Collections.Generic;using MiniJSON;public class MyGameObject: MonoBehaviour{ void Start() { var manifest = (TextAsset) Resources.Load("UnityCloudBuildManifest.json"); if (manifest != null) { var manifestDict = Json.Deserialize(manifest.text) as Dictionary<string,object>; foreach (var kvp in manifestDict) { // Be sure to check for null values! var value = (kvp.Value != null) ? kvp.Value.ToString() : ""; Debug.Log(string.Format("Key: {0}, Value: {1}", kvp.Key, value)); } } }}

ビルドマニフェストを ScriptableObject とする

BuildManifestObject
は、
UnityCloudBuildManifest.json
TextAsset を手動でロードせずに、スクリプトからビルドマニフェストの値にアクセスするために使用する
ScriptableObject
です。
BuildManifestObject
は、
UnityCloudBuildManifest.json
TextAsset が書き込まれていない場合に Build Automation によって呼び出されるエクスポート前の任意のパラメーターです。詳細は、 JSON 形式のマニフェスト を参照してください。
以下の C# コード例は、エクスポート前のメソッドを示しています。これは、マニフェストで指定された
buildNumber
に基づいて
PlayerSettings
bundleVersion
を更新します。エクスポート前メソッドの詳細については、エクスポート前メソッドとエクスポート後メソッド を参照してください。
using UnityEngine;using UnityEditor;using System;public class CloudBuildHelper : MonoBehaviour{ #if UNITY_CLOUD_BUILD public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest) { PlayerSettings.bundleVersion = string.Format("1.0.{0}", manifest.GetValue<int>("buildNumber")); } #endif}
以下は、
BuildManifestObject
クラスの public インターフェースです。
namespace UnityEngine.CloudBuild{ public class BuildManifestObject : ScriptableObject { // Try to get a manifest value - returns true if key was found and could be cast to type T, otherwise returns false. public bool TryGetValue<T>(string key, out T result); // Retrieve a manifest value or throw an exception if the given key isn't found. public T GetValue<T>(string key); // Set the value for a given key. public void SetValue(string key, object value); // Copy values from a dictionary. ToString() will be called on dictionary values before being stored. public void SetValues(Dictionary<string, object> sourceDict); // Remove all key/value pairs. public void ClearValues(); // Return a dictionary that represents the current BuildManifestObject. public Dictionary<string, object> ToDictionary(); // Return a JSON formatted string that represents the current BuildManifestObject public string ToJson(); // Return an INI formatted string that represents the current BuildManifestObject public override string ToString(); }}