/// <summary> /// Converts a SerializedProperty to a VtValue, for writing to USD. /// </summary> static public pxr.VtValue PropToVtValue(SerializedProperty prop) { switch (prop.propertyType) { case SerializedPropertyType.AnimationCurve: // TODO: needs to be broken down into atoms. return(new pxr.VtValue()); case SerializedPropertyType.ArraySize: return(prop.intValue); case SerializedPropertyType.Boolean: return(prop.boolValue); case SerializedPropertyType.Bounds: return(UnityTypeConverter.BoundsToVtArray(prop.boundsValue)); case SerializedPropertyType.BoundsInt: // TODO: add this to UnityTypeConverter. var bi = prop.boundsIntValue; var bnds = new Bounds(bi.center, bi.size); return(UnityTypeConverter.BoundsToVtArray(bnds)); case SerializedPropertyType.Character: return(prop.intValue); case SerializedPropertyType.Color: return(UnityTypeConverter.ColorToVec4f(prop.colorValue)); case SerializedPropertyType.Enum: return(prop.enumDisplayNames[prop.enumValueIndex]); case SerializedPropertyType.ExposedReference: // TODO. //return prop.exposedReferenceValue; return(new pxr.VtValue()); case SerializedPropertyType.FixedBufferSize: return(prop.fixedBufferSize); case SerializedPropertyType.Float: return(prop.floatValue); case SerializedPropertyType.Generic: return("GENERIC"); case SerializedPropertyType.Gradient: // TODO: gradientValue accessor is not public. wat? return("Gradient"); case SerializedPropertyType.Integer: return(prop.intValue); case SerializedPropertyType.LayerMask: return(prop.intValue); case SerializedPropertyType.ObjectReference: var obj = prop.objectReferenceValue; if (obj == null) { return(new pxr.VtValue("")); } // For object references in the scene, the asset path will be empty/null. // However, for mesh and material instances in the scen, what do we want to do here? // They are serialized to .unity files with just a file id, rather than fileid, pathid, and guid. string assetPath = AssetDatabase.GetAssetPath(prop.objectReferenceValue); if (string.IsNullOrEmpty(assetPath)) { return(new pxr.VtValue("")); } var fileId = prop.FindPropertyRelative("m_FileID").intValue; var pathId = prop.FindPropertyRelative("m_PathID").intValue; string guid = AssetDatabase.AssetPathToGUID(assetPath); return(prop.FindPropertyRelative("m_PathID").intValue + ":" + guid + ":" + fileId); case SerializedPropertyType.Quaternion: return(UnityTypeConverter.QuaternionToQuatf(prop.quaternionValue)); case SerializedPropertyType.Rect: return(UnityTypeConverter.RectToVtVec4(prop.rectValue)); case SerializedPropertyType.RectInt: // TODO: add this to UnityTypeConverter. var ri = prop.rectIntValue; return(new pxr.GfVec4i(ri.x, ri.y, ri.width, ri.height)); case SerializedPropertyType.String: return(prop.stringValue); case SerializedPropertyType.Vector2: return(UnityTypeConverter.Vector2ToVec2f(prop.vector2Value)); case SerializedPropertyType.Vector2Int: // TODO: add this to UnityTypeConverter. return(new pxr.GfVec2i(prop.vector2IntValue.x, prop.vector2IntValue.y)); case SerializedPropertyType.Vector3: return(UnityTypeConverter.Vector3ToVec3f(prop.vector3Value)); case SerializedPropertyType.Vector3Int: var v3 = prop.vector3IntValue; // TODO: add this to UnityTypeConverter. return(new pxr.GfVec3i(v3.x, v3.y, v3.z)); case SerializedPropertyType.Vector4: return(UnityTypeConverter.Vector4ToVec4f(prop.vector4Value)); } return("UNKNOWN"); }