From f2a652a75fbfe73567b5fe83613712bec0013a73 Mon Sep 17 00:00:00 2001 From: Saeed Barari Date: Thu, 18 Jul 2024 23:43:05 +0330 Subject: [PATCH] Fix SerializeReference on non serializable collections (#167) --- .../TriUnitySerializationUtilities.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Editor/Utilities/TriUnitySerializationUtilities.cs b/Editor/Utilities/TriUnitySerializationUtilities.cs index 2546f4f..fc0e4e0 100644 --- a/Editor/Utilities/TriUnitySerializationUtilities.cs +++ b/Editor/Utilities/TriUnitySerializationUtilities.cs @@ -27,7 +27,27 @@ public static bool IsSerializableByUnity(FieldInfo fieldInfo) if (fieldInfo.GetCustomAttribute() != 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() != null)