我有一个问题,我不知道如何解决它。所以我有一个自定义检查器,我想在一个没有inhert的类上,比如一个自定义变量。在这里,我将展示代码,希望您理解
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(QuizHolder))]
public class QuizHolderInspector : Editor {
public override void OnInspectorGUI()
{
QuizHolder myScript = (QuizHolder)target;//This produces a squigly line, and makes the error : "Cannot convert type 'UnityEngine.Object' to 'QuizHolder'"
MakePublic("m_Script");
MakePublic("NameOfQuizHolder");
MakePublic("Whichquiz");
//if (qui == QuizHolder.WhichQuiz.NumberQuiz)
//{
//}
}
void MakePublic(string smart)
{
var property2 = serializedObject.FindProperty(smart);
serializedObject.Update();
EditorGUILayout.PropertyField(property2, true);
serializedObject.ApplyModifiedProperties();
}
}`
quizholder代码也是:`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class QuizHolder {//As you see here, it doesnt inherit monodevolep, and i think that is the problem, but i don't know how to fix it since i need it to not inherit monodevolep
public string NameOfQuizHolder;
public enum WhichQuiz {NumberQuiz,OptionQuiz,InputFieldQuiz};
public WhichQuiz Whichquiz;
public NumberQuiz Numberquiz;
public OptionQuiz Optionquiz;
public InputFieldQuiz InputFieldquiz;
}`
请帮助我,我有点累了,如果它没有意义,那就很抱歉。 感谢
答案 0 :(得分:2)
你不能这样做。
至少您的QuizHolder
需要扩展Component
,否则无法将其附加到GameObject。
如果问题是它需要是编辑器脚本的序列化字段,那么它需要至少延伸UnityEngine.Object
(UnityEngine.Object
与System.Object
不同,这是所有类默认继承的内容。)
我只有大约80%的人确信后一种情况是你的问题,但对我来说并不完全清楚。这个假设是由于您的评论"Cannot convert type 'UnityEngine.Object' to 'QuizHolder'"