我正在尝试像{/ p>那样扩展UnityEngine.UI.Image
public class MyImage : Image {
public string Comment;
}
但是我在检查员中看不到额外的文本字段Comment
。是否可以添加检查员可用的额外字段?
PS 它触发了Extending Unity UI components with custom Inspector的重复但不是愚蠢的。我对custom Inspector
没有任何疑问。它只是default Inspector
的常规字段。问题是该领域根本没有出现在检查员身上。
答案 0 :(得分:5)
不幸的是,Inspector GUI无法自动从基类继承。您需要自己编写,就像Extending Unity UI components with custom Inspector中描述的那样。
MyImage.cs
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class MyImage : Image
{
public string Comment;
}
MyImageEditor.cs
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(MyImage))]
public class MyImageEditor : UnityEditor.UI.ImageEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();//Draw inspector UI of ImageEditor
MyImage image = (MyImage)target;
image.Comment = EditorGUILayout.TextField("Comment", image.Comment);
}
}