我如何通过反思从一个类派生出来?以下内容适用于获取现有实例以及创建类的新实例。
public class TreeViewSHWinstances {
[MenuItem("Reflect/CreateSHWinstances")]
static void Activate() {
Main();
}
static void Main() {
Assembly asm = typeof(UnityEditor.EditorWindow).Assembly;
Type wndType = asm.GetType ("UnityEditor.SceneHierarchyWindow");
// Grabs an existing instance if it exists and then sets the focus to it.
EditorWindow exstWnd = EditorWindow.GetWindow (wndType);
// Always create a new instance regardless if one already exists.
EditorWindow newWnd = (EditorWindow)Activator.CreateInstance (wndType);
}
}
这就是我真正想要做的事情,但显然程序集尚未加载,当我试图从上面的类中获取它时,我得到一个错误,表明它不是一个类型,即使我正在请求wndType
// THIS IS NOT INTENDED TO NOR DOES IT WORK.
public MySceneHierarchyWindow : UnityEditor.SceneHierarchyWindow {
}
我的猜测是以某种方式使用Emit,但我在尝试之后我不确定这是正确的方向。