Skip to content

Commit

Permalink
Fix SerializeReference on non serializable collections (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
somedeveloper00 authored Jul 18, 2024
1 parent 6c844f0 commit f2a652a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Editor/Utilities/TriUnitySerializationUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,27 @@ public static bool IsSerializableByUnity(FieldInfo fieldInfo)

if (fieldInfo.GetCustomAttribute<SerializeReference>() != null)
{
return true;
// if it's a list or array, the base type should be serializable
if (fieldInfo.FieldType.IsArray)
{
var type = fieldInfo.FieldType.GetElementType();
if (type.IsSerializable || type.IsInterface)
return true;
else
return false;
}
else if (fieldInfo.FieldType.IsGenericType && fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(List<>))
{
var type = fieldInfo.FieldType.GenericTypeArguments[0];
if (type.IsSerializable || type.IsInterface)
return true;
else
return false;
}
else
{
return true;
}
}

if (fieldInfo.IsPublic || fieldInfo.GetCustomAttribute<SerializeField>() != null)
Expand Down

0 comments on commit f2a652a

Please sign in to comment.