/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ using System; using UnityEngine; namespace Live2D.Cubism.Framework.Json { /// /// Handles display info from cdi3.json. /// [Serializable] public sealed class CubismDisplayInfo3Json { /// /// Loads a cdi3.json. /// /// cdi3.json to deserialize. /// Deserialized cdi3.json on success; otherwise. public static CubismDisplayInfo3Json LoadFrom(string cdi3Json) { if (string.IsNullOrEmpty(cdi3Json)) { return null; } var ret = JsonUtility.FromJson(cdi3Json); // Parse CombinedParameters. // Unity is unable to parse the double array. var value = CubismJsonParser.ParseFromString(cdi3Json); // Return early if there is no references. if (value.Get("CombinedParameters") == null) { return ret; } // Get CombinedParameters from json data. var rawCombinedParameters = value.Get("CombinedParameters").GetVector(null); ret.CombinedParameters = new SerializableCombinedParameterIds[rawCombinedParameters.Count]; for (var combinedParameterIndex = 0; combinedParameterIndex < rawCombinedParameters.Count; combinedParameterIndex++) { var combinedParameter = rawCombinedParameters[combinedParameterIndex]; var ids = new string[combinedParameter.GetVector(null).Count]; // Set ids. for (var idIndex = 0; idIndex < ids.Length; idIndex++) { ids.SetValue(combinedParameter.GetVector(null)[idIndex].toString(), idIndex); } // Set combined parameters. ret.CombinedParameters[combinedParameterIndex] = new SerializableCombinedParameterIds { Ids = ids }; } return ret; } #region Json Data /// /// Json file format version. /// [SerializeField] public int Version; /// /// Array of model parameters. /// [SerializeField] public SerializableParameters[] Parameters; /// /// Array of ParameterGroups. /// [SerializeField] public SerializableParameterGroups[] ParameterGroups; /// /// Array of Parts. /// [SerializeField] public SerializableParts[] Parts; [SerializeField] public SerializableCombinedParameterIds[] CombinedParameters; #endregion #region Json Helpers [Serializable] public struct SerializableParameters { /// /// The ID of the parameter. /// [SerializeField] public string Id; /// /// The Group ID of the parameter. /// [SerializeField] public string GroupId; /// /// The Name of the parameter. /// [SerializeField] public string Name; } [Serializable] public struct SerializableParameterGroups { /// /// The ID of the parameter. /// [SerializeField] public string Id; /// /// The Group ID of the parameter. /// [SerializeField] public string GroupId; /// /// The Name of the parameter. /// [SerializeField] public string Name; } [Serializable] public struct SerializableParts { /// /// The ID of the part. /// [SerializeField] public string Id; /// /// The Name of the part. /// [SerializeField] public string Name; } [Serializable] public struct SerializableCombinedParameterIds { /// /// The ID of the part. /// [SerializeField] public string[] Ids; } [Serializable] public struct CombinedParameter { /// /// The Id of the parameter that becomes the X-axis when combined. /// [SerializeField] public string HorizontalParameterId; /// /// The Id of the parameter that becomes the Y-axis when combined. /// [SerializeField] public string VerticalParameterId; } #endregion } }