Version: 2021.3
JSON 格式的编译清单
计划构建

ScriptableObject 格式的编译清单

BuildManifestObject is a ScriptableObject you can use to access the values in the Build manifest via script, without needing to manually load the UnityCloudBuildManifest.json TextAsset.

It is an optional parameter to the pre-export invoked by Cloud Build, if the UnityCloudBuildManifest.json TextAsset has not been written. For more information, see Manifest as JSON.

The following example C# code demonstrates a pre-export method that updates the bundleVersion in PlayerSettings based on the buildNumber provided in the manifest. For more information on pre-export methods, see Pre- and Post-export methods.

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 类的公有接口:

namespace UnityEngine.CloudBuild
{
    public class BuildManifestObject : ScriptableObject
    {
        // 尝试获取清单值 - 如果找到键并且可以转换为类型 T,则返回 true,否则返回 false。
        public bool TryGetValue<T>(string key, out T result);
        //检索清单值,如果找不到给定的键,则抛出异常。
        public T GetValue<T>(string key);
        //设置给定键的值。
        public void SetValue(string key, object value);
        //从字典复制值。在保存字典值之前将对字典值调用 ToString()。
        public void SetValues(Dictionary<string, object> sourceDict);
        //删除所有键/值对。
        public void ClearValues();
        //返回代表当前 BuildManifestObject 的字典。
        public Dictionary<string, object> ToDictionary();
        //返回代表当前 BuildManifestObject 的 JSON 格式字符串
        public string ToJson();
        // 返回代表当前 BuildManifestObject 的 INI 格式字符串
        public override string ToString();
    }
}
JSON 格式的编译清单
计划构建