/// <summary> /// Constructs Unity SerializedProperties from USD. /// </summary> static void PropertyFromUsd(pxr.UsdPrim prim, SerializedProperty prop, System.Text.StringBuilder sb, string propPrefix) { if (prim == null) { Debug.LogError("Null prim - " + propPrefix); } if (!prim.IsValid()) { Debug.LogError("Invalid prim: " + prim.GetPath().ToString()); } string prefix = ""; try { var nameStack = new List <string>(); nameStack.Add("unity"); if (!string.IsNullOrEmpty(propPrefix)) { nameStack.Add(propPrefix); } string lastName = ""; int lastDepth = 0; while (prop.Next(prop.propertyType == SerializedPropertyType.Generic && !prop.isArray)) { string tabIn = ""; for (int i = 0; i < prop.depth; i++) { tabIn += " "; } if (prop.depth > lastDepth) { Debug.Assert(lastName != ""); nameStack.Add(lastName); } else if (prop.depth < lastDepth) { nameStack.RemoveRange(nameStack.Count - (lastDepth - prop.depth), lastDepth - prop.depth); } lastDepth = prop.depth; lastName = prop.name; if (nameStack.Count > 0) { prefix = string.Join(":", nameStack.ToArray()); prefix += ":"; } else { prefix = ""; } sb.Append(tabIn + prefix + prop.name + "[" + prop.propertyType.ToString() + "] = "); if (prop.isArray && prop.propertyType != SerializedPropertyType.String) { // TODO. sb.AppendLine("ARRAY"); } else if (prop.propertyType == SerializedPropertyType.Generic) { sb.AppendLine("Generic"); } else if (prop.propertyType == SerializedPropertyType.AnimationCurve || prop.propertyType == SerializedPropertyType.Gradient) { // TODO. sb.AppendLine(NativeSerialization.ValueToString(prop)); } else { sb.AppendLine(NativeSerialization.ValueToString(prop)); var attrName = new pxr.TfToken(prefix + prop.name); var attr = prim.GetAttribute(attrName); if (attr == null) { Debug.LogError("Null attr: " + prim.GetPath().ToString() + "." + attrName.ToString()); } if (!attr.IsValid()) { Debug.LogError("Attribute not found:" + attr.GetPath().ToString()); } NativeSerialization.VtValueToProp(prop, attr.Get(0)); } } } catch { Debug.LogWarning("Failed on: " + prim.GetPath() + "." + prefix + prop.name); throw; } }