0

我正在 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.EditorPlugin1.Component1EditorPlugin1.Component1Editor

Plugin2.Component1Editor在编译时不会冲突Plugin1.Component1Editor,因为它有自己的命名空间。但是 Unity 检查器中实际发生了什么?

我测试它时的行为是所需的行为:Plugin2.Component1Editor呈现检查器,除非Plugin2未安装。但为什么?我不想相信它会继续这样做,除非我知道为什么。

谢谢!

编辑:我错了,它没有渲染Plugin2.Component1Editor,它是默认的 Unity 编辑器运行。我的自定义编辑器都没有使用。如何指定要使用哪一个?

4

1 回答 1

0

似乎解决方案确实是继承。

我将序列化的属性设置为由处理Plugin1.Component1Editor和检索受保护而不是私有,然后Plugin2.Component1Editor继承自Plugin1.Component1Editor而不是UnityEditor.Editor. 然后Plugin2.Component1Editor成为渲染之一,Plugin1.Component1Editor根据需要调用 。

解决方案的主要部分是我OnEnable调用 in Plugin1.Component1Editor,它检索受保护的序列化属性,以便我可以从Plugin2.Component1Editorvia调用它base.OnEnable()

于 2017-08-23T06:16:47.337 回答