Reputation: 4661
I'm writing a DecoratorDrawer
that allows to give long, meaningfull descriptions for any field in the inspector. I'm aiming for a look like this:
(faked in gimp)
That is want a bit lighter background, a rounded border etc.
There are places in the Editor that use this style, for example there are two instances in the lightmapping window:
I can't use EditorGUI.HelpBox
because:
I cannot reliably measure the height of contents of the HelpBox
. Note that the drawers forbid using EditorGUILayout
.
There is no rich text or other way to style the content
Images aren't permited - i'd like to have them as an option later on
Using HelpBox
it looks like this:
My question is: is there a hardcoded GUIStyle
or UnityEditor
/UnityEditorInternal
method that allows for displaying information in this style? If not, any idea on how to fake this style? How to make the rounded corners? Remember that there is a pro skin that looks different, so it'd be nice if the solution would work on both skins.
Upvotes: 2
Views: 8443
Reputation: 21
The best way I've found is by passing EditorStyles.helpBox to the constructor.
style = new GUIStyle(EditorStyles.helpBox);
style.richText = true;
This way, you wont affect EditorStyles.helpBox by making changes to the style.
Upvotes: 2
Reputation: 20038
You can retrieve the HelpBox style by getting it from GUI.skin
.
Something like
EditorGUILayout.TextArea("This is my text", GUI.skin.GetStyle("HelpBox"));
will get you
Note that this will still not allow you to have rich text though. It's disabled by default. To enable it, you can do something like
GUIStyle myStyle = GUI.skin.GetStyle("HelpBox");
myStyle.richText = true;
EditorGUILayout.TextArea("This is my text <b>AND IT IS BOLD</b>", myStyle);
which will result in
Upvotes: 7