Browse Source

Merge pull request #754 from stevehalliwell/FindTypesOutsideAssembly

EditorUtils.FindDerivedTypes now finds within ALL assembles
master
Steve Halliwell 5 years ago committed by GitHub
parent
commit
852df44030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      Assets/Fungus/Scripts/Editor/EditorExtensions.cs

19
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
}
/// <summary>
/// A convenient method for calling the above.
/// A convenient method for calling the above, but for ALL assemblies.
/// Example usage:
/// List<System.Type> subTypes = EditorUtility.FindDerivedTypes(typeof(BaseTimelineEvent)).ToList();
/// </summary>
@ -61,7 +62,21 @@ namespace Fungus.EditorUtils
/// <returns></returns>
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
}
}
}
Loading…
Cancel
Save