- Home /
Get all inherited classes of an abstract class - Editor Scripting
This question and answer: http://stackoverflow.com/questions/5411694/get-all-inherited-classes-of-an-abstract-class
Except that, apparently, the "Assembly" object doesn't exist in the context of the UnityEditor.
Ideas?
Usage: Working on a custom Event Handler with user defined behaviors, and in the Custom Inspector when you hit "Add Behavior" I want to pop a list of possible behaviors, but I don't want to have some kind of actual list anywhere - ideally, you only have to define the new behavior (and inherit from the Behavior abstract class), and everything is taken care of.
Update:
Via Jordan's answer below, here's the working, compact version `using System.Linq` and `using System.Reflection`:
System.Type[] types = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
System.Type[] possible = (from System.Type type in types where type.IsSubclassOf(typeof(BaseClass)) select type).ToArray();
Answer by Landern · Dec 14, 2012 at 02:41 AM
You need to add the namespace where the Assembly(in System.Reflection) type exists. Place the using/import at the top of the script.
c#
using System.Reflection;
js
import System.Reflection;
For c#, you can skip the `using` and just `System.Reflection.Assembly`
Your answer
Follow this Question
Related Questions
Building a Collection of Subclasses and Modifying Their Public Members from the Inspector 0 Answers
Get name of inherited type? 1 Answer
Draw Custom Inspector for base and child classes, but add default Inspector for child classes 0 Answers
how to apply same fields for objects with different script but inherit same class Unity C# 1 Answer