@@ -26,49 +26,47 @@ public static bool TryGetPropertyDrawer (Type type,out PropertyDrawer drawer)
26
26
static Type GetCustomPropertyDrawerType ( Type type )
27
27
{
28
28
Type [ ] interfaceTypes = type . GetInterfaces ( ) ;
29
-
30
- foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
29
+
30
+ var types = TypeCache . GetTypesWithAttribute < CustomPropertyDrawer > ( ) ;
31
+ foreach ( Type drawerType in types )
31
32
{
32
- foreach ( Type drawerType in assembly . GetTypes ( ) )
33
+ var customPropertyDrawerAttributes = drawerType . GetCustomAttributes ( typeof ( CustomPropertyDrawer ) , true ) ;
34
+ foreach ( CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes )
33
35
{
34
- var customPropertyDrawerAttributes = drawerType . GetCustomAttributes ( typeof ( CustomPropertyDrawer ) , true ) ;
35
- foreach ( CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes )
36
+ var field = customPropertyDrawer . GetType ( ) . GetField ( "m_Type" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
37
+ if ( field != null )
36
38
{
37
- var field = customPropertyDrawer . GetType ( ) . GetField ( "m_Type" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
38
- if ( field != null )
39
+ var fieldType = field . GetValue ( customPropertyDrawer ) as Type ;
40
+ if ( fieldType != null )
39
41
{
40
- var fieldType = field . GetValue ( customPropertyDrawer ) as Type ;
41
- if ( fieldType != null )
42
+ if ( fieldType == type )
42
43
{
43
- if ( fieldType == type )
44
- {
45
- return drawerType ;
46
- }
47
-
48
- // If the property drawer also allows for being applied to child classes, check if they match
49
- var useForChildrenField = customPropertyDrawer . GetType ( ) . GetField ( "m_UseForChildren" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
50
- if ( useForChildrenField != null )
44
+ return drawerType ;
45
+ }
46
+
47
+ // If the property drawer also allows for being applied to child classes, check if they match
48
+ var useForChildrenField = customPropertyDrawer . GetType ( ) . GetField ( "m_UseForChildren" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
49
+ if ( useForChildrenField != null )
50
+ {
51
+ object useForChildrenValue = useForChildrenField . GetValue ( customPropertyDrawer ) ;
52
+ if ( useForChildrenValue is bool && ( bool ) useForChildrenValue )
51
53
{
52
- object useForChildrenValue = useForChildrenField . GetValue ( customPropertyDrawer ) ;
53
- if ( useForChildrenValue is bool && ( bool ) useForChildrenValue )
54
+ // Check interfaces
55
+ if ( Array . Exists ( interfaceTypes , interfaceType => interfaceType == fieldType ) )
54
56
{
55
- // Check interfaces
56
- if ( Array . Exists ( interfaceTypes , interfaceType => interfaceType == fieldType ) )
57
+ return drawerType ;
58
+ }
59
+
60
+ // Check derived types
61
+ Type baseType = type . BaseType ;
62
+ while ( baseType != null )
63
+ {
64
+ if ( baseType == fieldType )
57
65
{
58
66
return drawerType ;
59
67
}
60
68
61
- // Check derived types
62
- Type baseType = type . BaseType ;
63
- while ( baseType != null )
64
- {
65
- if ( baseType == fieldType )
66
- {
67
- return drawerType ;
68
- }
69
-
70
- baseType = baseType . BaseType ;
71
- }
69
+ baseType = baseType . BaseType ;
72
70
}
73
71
}
74
72
}
0 commit comments