diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/PropertyDrawerCache.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/PropertyDrawerCache.cs index 415dd3b..df1bf09 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/PropertyDrawerCache.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/PropertyDrawerCache.cs @@ -26,49 +26,47 @@ public static bool TryGetPropertyDrawer (Type type,out PropertyDrawer drawer) static Type GetCustomPropertyDrawerType (Type type) { Type[] interfaceTypes = type.GetInterfaces(); - - foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) + + var types = TypeCache.GetTypesWithAttribute(); + foreach (Type drawerType in types) { - foreach (Type drawerType in assembly.GetTypes()) + var customPropertyDrawerAttributes = drawerType.GetCustomAttributes(typeof(CustomPropertyDrawer), true); + foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes) { - var customPropertyDrawerAttributes = drawerType.GetCustomAttributes(typeof(CustomPropertyDrawer), true); - foreach (CustomPropertyDrawer customPropertyDrawer in customPropertyDrawerAttributes) + var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance); + if (field != null) { - var field = customPropertyDrawer.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance); - if (field != null) + var fieldType = field.GetValue(customPropertyDrawer) as Type; + if (fieldType != null) { - var fieldType = field.GetValue(customPropertyDrawer) as Type; - if (fieldType != null) + if (fieldType == type) { - if (fieldType == type) - { - return drawerType; - } - - // If the property drawer also allows for being applied to child classes, check if they match - var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance); - if (useForChildrenField != null) + return drawerType; + } + + // If the property drawer also allows for being applied to child classes, check if they match + var useForChildrenField = customPropertyDrawer.GetType().GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance); + if (useForChildrenField != null) + { + object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer); + if (useForChildrenValue is bool && (bool)useForChildrenValue) { - object useForChildrenValue = useForChildrenField.GetValue(customPropertyDrawer); - if (useForChildrenValue is bool && (bool)useForChildrenValue) + // Check interfaces + if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType)) { - // Check interfaces - if (Array.Exists(interfaceTypes, interfaceType => interfaceType == fieldType)) + return drawerType; + } + + // Check derived types + Type baseType = type.BaseType; + while (baseType != null) + { + if (baseType == fieldType) { return drawerType; } - // Check derived types - Type baseType = type.BaseType; - while (baseType != null) - { - if (baseType == fieldType) - { - return drawerType; - } - - baseType = baseType.BaseType; - } + baseType = baseType.BaseType; } } }