From 6b7b97af384896a5abbb2a722216d0e73e52de9b Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Wed, 11 Sep 2019 18:32:23 +1000 Subject: [PATCH] EditorUtils.FindDerivedTypes now finds within ALL assembles -Uses TypeCache if available --- .../Fungus/Scripts/Editor/EditorExtensions.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/EditorExtensions.cs b/Assets/Fungus/Scripts/Editor/EditorExtensions.cs index 20028c7c..cce6da06 100644 --- a/Assets/Fungus/Scripts/Editor/EditorExtensions.cs +++ b/Assets/Fungus/Scripts/Editor/EditorExtensions.cs @@ -4,6 +4,7 @@ using UnityEngine; using System.Collections.Generic; using System.Linq; +using UnityEditor; namespace Fungus.EditorUtils { @@ -52,7 +53,7 @@ namespace Fungus.EditorUtils } /// - /// A convenient method for calling the above. + /// A convenient method for calling the above, but for ALL assemblies. /// Example usage: /// List subTypes = EditorUtility.FindDerivedTypes(typeof(BaseTimelineEvent)).ToList(); /// @@ -61,7 +62,21 @@ namespace Fungus.EditorUtils /// public static System.Type[] FindDerivedTypes(System.Type baseType, bool classOnly = true) { - return FindDerivedTypesFromAssembly(System.Reflection.Assembly.GetAssembly(baseType), baseType, classOnly); +#if UNITY_2019_2_OR_NEWER + var results = TypeCache.GetTypesDerivedFrom(baseType).ToArray(); + if (classOnly) + return results.Where(x => x.IsClass).ToArray(); + else + return results.ToArray(); +#else + System.Type[] typeArray = new System.Type[0]; + var retval = typeArray.Concat(typeArray); + foreach (var assem in System.AppDomain.CurrentDomain.GetAssemblies()) + { + retval = retval.Concat(FindDerivedTypesFromAssembly(assem, baseType, classOnly)); + } + return retval.ToArray(); +#endif } } } \ No newline at end of file