mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-09 04:19:42 -05:00
use EnumSerializationType. fix gltf.cameras[].type Serialization
* https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/MultiUVTest/glTF/MultiUVTest.gltf#L192
This commit is contained in:
@@ -51,26 +51,26 @@ namespace UniGLTF
|
||||
Path = path + "/" + fi.Name;
|
||||
m_attr = fi.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(JsonSchemaAttribute)) as JsonSchemaAttribute;
|
||||
|
||||
Serialization = GetSerialization(m_fi.FieldType, Path);
|
||||
Serialization = GetSerialization(m_fi.FieldType, Path, m_attr);
|
||||
}
|
||||
|
||||
static IValueSerialization GetSerialization(Type t, string path)
|
||||
static IValueSerialization GetSerialization(Type t, string path, JsonSchemaAttribute attr)
|
||||
{
|
||||
if (t.IsArray)
|
||||
{
|
||||
return new ArraySerialization(t,
|
||||
GetSerialization(t.GetElementType(), path + "[]"));
|
||||
GetSerialization(t.GetElementType(), path + "[]", attr));
|
||||
}
|
||||
else if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
return new ListSerialization(t,
|
||||
GetSerialization(t.GetGenericArguments()[0], path + "[]"));
|
||||
GetSerialization(t.GetGenericArguments()[0], path + "[]", attr));
|
||||
}
|
||||
else if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>)
|
||||
&& t.GetGenericArguments()[0] == typeof(string))
|
||||
{
|
||||
return new StringKeyDictionarySerialization(t,
|
||||
GetSerialization(t.GetGenericArguments()[1], path));
|
||||
return new StringKeyDictionarySerialization(t,
|
||||
GetSerialization(t.GetGenericArguments()[1], path, attr));
|
||||
}
|
||||
|
||||
// GetCollectionType(fi.FieldType, out suffix, out t);
|
||||
@@ -124,7 +124,7 @@ namespace UniGLTF
|
||||
}
|
||||
else if (t.IsEnum)
|
||||
{
|
||||
return new EnumIntSerialization(t);
|
||||
return new EnumIntSerialization(t, attr.EnumSerializationType);
|
||||
}
|
||||
|
||||
return new ObjectSerialization(t, path);
|
||||
|
||||
@@ -179,20 +179,33 @@ namespace UniGLTF
|
||||
public class EnumIntSerialization : PrimitiveSerializationBase
|
||||
{
|
||||
Type m_type;
|
||||
UniJSON.EnumSerializationType m_serializationType;
|
||||
|
||||
public override Type ValueType
|
||||
{
|
||||
get { return m_type; }
|
||||
}
|
||||
|
||||
public EnumIntSerialization(Type t)
|
||||
public EnumIntSerialization(Type t, UniJSON.EnumSerializationType serializationType)
|
||||
{
|
||||
m_type = t;
|
||||
m_serializationType = serializationType;
|
||||
}
|
||||
|
||||
public override string GenerateDeserializerCall(string callName, string argName)
|
||||
{
|
||||
return string.Format("({0}){1}.GetInt32()", m_type.Name, argName);
|
||||
switch (m_serializationType)
|
||||
{
|
||||
case UniJSON.EnumSerializationType.AsInt:
|
||||
return string.Format("({0}){1}.GetInt32()", m_type.Name, argName);
|
||||
|
||||
case UniJSON.EnumSerializationType.AsLowerString:
|
||||
// (ProjectionType)Enum.Parse(typeof(ProjectionType), kv.Value.GetString(), true)
|
||||
return $"({m_type.Name})Enum.Parse(typeof({m_type.Name}), {argName}.GetString(), true)";
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1861,7 +1861,7 @@ public static glTFCamera Deserialize_gltf_cameras_LIST(ListTreeNode<JsonValue> p
|
||||
}
|
||||
|
||||
if(key=="type"){
|
||||
value.type = (ProjectionType)kv.Value.GetInt32();
|
||||
value.type = (ProjectionType)Enum.Parse(typeof(ProjectionType), kv.Value.GetString(), true);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user