ランタイム中に Build Automation のビルドマニフェストを使用
Access build manifest data at runtime for analytics and bug reporting in Unity Build Automation.
読み終わるまでの所要時間 2 分最終更新 1ヶ月前
ゲームのランタイムコードが、ビルド自体に関する主要な情報を把握していると、多くの場合に役立ちます。ビルドの名前や番号などの情報は、バグの報告や分析情報の追跡に非常に役立ちます。これを支援するために、Build Automation ではビルド時にゲームにマニフェストを挿入し、後のランタイム時にこの主要データにアクセスできるようにします。 Build Automation は、マニフェストを JSON 形式の
TextAssetResources.Load()値 | プロパティ |
|---|---|
| ビルドされたコミットまたは変更リスト。 |
| ビルドされたブランチの名前。 |
| このビルドに対応する Build Automation ビルド番号。 |
| ビルドプロセスが開始されたときの UTC タイムスタンプ。 |
| Unity プロジェクト ID。 |
| Build Automation で構成された |
| Build Automation がビルドの作成に使用した Unity のバージョン。 |
| プロジェクトのビルドに使用された XCode のバージョン (iOS のみ)。 |
| ビルドされたビルドターゲットの名前。 |
Assets/UnityCloud/Resourcesローカルテスト用
ビルドマニフェスト機能をローカルでテストするには、ファイルにUnityCloudBuildManifest.json.txtマニフェストの使用
ランタイムにマニフェストにアクセスするには、以下を使用します。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 とする
BuildManifestObjectUnityCloudBuildManifest.jsonScriptableObjectBuildManifestObjectUnityCloudBuildManifest.jsonbuildNumberPlayerSettingsbundleVersion以下は、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}
BuildManifestObjectnamespace 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(); }}