77using UnityEditor ;
88using Object = UnityEngine . Object ;
99
10- [ assembly: InternalsVisibleTo ( "Toolbox.Editor.Tests" ) ]
11-
1210namespace Toolbox . Editor
1311{
1412 public static partial class PropertyUtility
@@ -27,7 +25,9 @@ internal static bool HasModifedProperties(this SerializedProperty property)
2725 internal static string GetPropertyHashKey ( this SerializedProperty property )
2826 {
2927 var hash = property . serializedObject . GetHashCode ( ) ;
30- return string . Format ( "{0}.{1}" , hash , property . propertyPath ) ;
28+ return property . propertyType != SerializedPropertyType . ManagedReference
29+ ? $ "{ hash } .{ property . propertyPath } "
30+ : $ "{ hash } .{ property . propertyPath } .{ property . managedReferenceFieldTypename } ";
3131 }
3232
3333 /// <summary>
@@ -36,7 +36,9 @@ internal static string GetPropertyHashKey(this SerializedProperty property)
3636 internal static string GetPropertyTypeKey ( this SerializedProperty property )
3737 {
3838 var type = property . serializedObject . targetObject . GetType ( ) ;
39- return string . Format ( "{0}.{1}" , type , property . propertyPath ) ;
39+ return property . propertyType != SerializedPropertyType . ManagedReference
40+ ? $ "{ type } .{ property . propertyPath } "
41+ : $ "{ type } .{ property . propertyPath } .{ property . managedReferenceFieldTypename } ";
4042 }
4143
4244 /// <summary>
@@ -253,7 +255,7 @@ internal static FieldInfo GetFieldInfo(this SerializedProperty property, out Typ
253255
254256 internal static FieldInfo GetFieldInfo ( this SerializedProperty property , out Type propertyType , Object target )
255257 {
256- return GetFieldInfoFromProperty ( target . GetType ( ) , property . propertyPath , out propertyType ) ;
258+ return GetFieldInfoFromProperty ( property , out propertyType , target . GetType ( ) ) ;
257259 }
258260
259261 public static FieldInfo GetFieldInfoFromProperty ( SerializedProperty property , out Type type )
@@ -265,14 +267,15 @@ public static FieldInfo GetFieldInfoFromProperty(SerializedProperty property, ou
265267 return null ;
266268 }
267269
268- return GetFieldInfoFromProperty ( classType , property . propertyPath , out type ) ;
270+ return GetFieldInfoFromProperty ( property , out type , classType ) ;
269271 }
270272
271- public static FieldInfo GetFieldInfoFromProperty ( Type host , string fieldPath , out Type type )
273+ public static FieldInfo GetFieldInfoFromProperty ( SerializedProperty property , out Type type , Type host )
272274 {
273275 FieldInfo field = null ;
274276 type = host ;
275277
278+ var fieldPath = property . propertyPath ;
276279 var members = GetPropertyFieldTree ( fieldPath , false ) ;
277280 for ( var i = 0 ; i < members . Length ; i ++ )
278281 {
@@ -287,10 +290,21 @@ public static FieldInfo GetFieldInfoFromProperty(Type host, string fieldPath, ou
287290 continue ;
288291 }
289292
293+ const BindingFlags fieldFlags = BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
290294 FieldInfo foundField = null ;
291295 for ( var currentType = type ; foundField == null && currentType != null ; currentType = currentType . BaseType )
292296 {
293- foundField = currentType . GetField ( member , BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ) ;
297+ foundField = currentType . GetField ( member , fieldFlags ) ;
298+ //NOTE: [SerializeReference] detected? If so we need to check dynamically cached type
299+ if ( foundField == null )
300+ {
301+ var parent = property . GetParent ( ) ;
302+ if ( parent != null && parent . propertyType == SerializedPropertyType . ManagedReference )
303+ {
304+ TypeUtilities . TryGetTypeFromManagedReferenceFullTypeName ( parent . managedReferenceFullTypename , out var parentType ) ;
305+ foundField = parentType . GetField ( member , fieldFlags ) ;
306+ }
307+ }
294308 }
295309
296310 if ( foundField == null )
0 commit comments