如果你想覆盖内置的文本资产检查器,你必须找到它并从你自己的编辑器中调用它。该类被调用UnityEditor.TextAssetInspector
,但它是一个私有内部类,通常只能由 Unity 在内部引用。但是,您可以使用反射访问它,如下所示:
使用系统;
使用 System.Reflection;
使用 UnityEngine;
使用 UnityEditor;
[自定义编辑器(typeof(TextAsset))]
公共类 TestInspector : 编辑器
{
私人编辑器 m_editor;
公共覆盖无效 OnInspectorGUI()
{
如果(m_editor == null)
{
var 程序集 = AppDomain.CurrentDomain.GetAssemblies();
foreach(程序集中的 var a)
{
var type = a.GetType("UnityEditor.TextAssetInspector");
如果(类型!= null)
{
m_editor = Editor.CreateEditor(目标,类型);
休息;
}
}
}
如果(m_editor != null)
m_editor.OnInspectorGUI();
}
}
这将在所有当前加载的程序集中搜索 type UnityEditor.TextAssetInspector
,然后为当前资产目标创建它的实例。我们使用Editor.CreateEditor
允许我们传入要创建的编辑器类型的版本,否则它将尝试创建TestInspector
.
请注意,这是假设有关 Unity 内部的某些事情,并且可能不适用于 Unity 的未来版本。