我在Unity 5.6中制作了一个基于插件的C#应用程序,有时可能会安装一些插件,有时则不会 .
在我的插件 Plugin1
中,我有一个组件 Plugin1.Component1
. 在同一个项目中,我为它实现了一个名为 Plugin1.Component1Editor
的自定义编辑器,即 [CustomEditor(typeof(Plugin1.Component1))]
. 安装 Plugin1
时, Component1
可用,并使用自定义编辑器进行渲染 .
我的插件 Plugin2
取决于 Plugin1
. 根据其组件 Plugin2.Component2
中的设置,它希望更改 Plugin1.Component1
的自定义编辑器 .
我在 Plugin2
中实现了一个名为 Plugin2.Component1Editor
的新自定义编辑器,它也是 [CustomEditor(typeof(Plugin1.Component1))]
. 它继承自 UnityEditor.Editor
,而不是 Plugin1.Component1Editor
,因为后者导致在 Plugin1.Component1Editor
中找不到序列化属性的问题 .
Plugin2.Component1Editor
在编译时不会与 Plugin1.Component1Editor
冲突,因为它有自己的命名空间 . 但Unity检查员实际发生了什么?
我测试它时的行为是所需的行为: Plugin2.Component1Editor
呈现检查器,除非未安装 Plugin2
. 但为什么?我不想相信它会继续这样做,除非我知道为什么 .
谢谢!
编辑:我错了,它没有呈现 Plugin2.Component1Editor
,它是默认的Unity编辑器运行 . 我的自定义编辑器都没有使用 . 如何指定我想使用哪一个?
1 回答
似乎解决方案确实是继承 .
我使序列化属性由
Plugin1.Component1Editor
处理并且它们的检索受保护而不是私有,然后Plugin2.Component1Editor
继承自Plugin1.Component1Editor
而不是UnityEditor.Editor
. 然后Plugin2.Component1Editor
成为渲染器,根据需要调用Plugin1.Component1Editor
.解决方案的主要部分是我在
Plugin1.Component1Editor
中调用了OnEnable
,它检索了受保护的序列化属性,以便我可以通过base.OnEnable()
从Plugin2.Component1Editor
调用它 .