【发布时间】:2018-07-08 09:38:25
【问题描述】:
我正在尝试修饰我的 Inspector,但在尝试在 Inspector 的指定位置绘制文本时遇到了很多麻烦。我在下面的示例检查器上绘制了一个彩色矩形,并希望在其上绘制文本(如标签)。
如何在上面显示的“X”位置绘制文本/标签?我不确定从哪里开始。任何帮助将不胜感激。
实施答案:
public override void OnGUI(Rect position)
{
GUIStyle myStyle = new GUIStyle();
myStyle.fontSize = 16;
myStyle.alignment = TextAnchor.UpperLeft;
myStyle.padding.top = 5;
myStyle.padding.left = -3;
myStyle.fontStyle = FontStyle.Bold;
Color32 color = colorSpacer.drawColor; // Custom Property Attribute
EditorGUI.DrawRect(new Rect(position.x-11, position.y, position.width+11, position.height-2), color);
Rect r = GUILayoutUtility.GetLastRect();
EditorGUI.LabelField(r, "Section Header", myStyle);
}
【问题讨论】:
-
请显示您的自定义检查器的实际代码,以便我可以指出在哪里添加插入标签的代码。