- Home /
Question by
Jehy · Jul 08, 2018 at 07:26 AM ·
inspectorcustom editoreditorguipropertydrawercustom inspector
Inspector Overlapping Text Label at a Position
I'm trying to spruce up my Inspector but I'm having a lot of trouble trying to draw text at a specified position in the inspector. I have drawn a colored rectangle on the inspector and want to draw text (like a label) on top of it.
How can I draw text/label at the "X" position shown above? Do I need to save my text into a texture and draw it that way?
capture2.png
(18.1 kB)
Comment
Best Answer
Answer by Jehy · Jul 08, 2018 at 04:05 PM
The solution for my issue was EditorGUI.LabelField. Following is the implementation:
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);
}
capture.png
(10.0 kB)