- Home /
Custom inspector: changing foldout's text color
Hello,
I built a custom inspector, but I can't find a way to change the Foldout element text color.
I created a custom GUIStyle to use (foldoutStyle = new GUIStyle(EditorStyles.foldout)
), and I'm trying to change its color via the usual foldoutStyle.[render state].textColor
property. The thing is, nothing happens.
I tried all the possible render settings (foldoutStyle.normal, hover, active, onNormal, onHover, onActive, focused, onFocused), but to no avail. Or better, setting the focused.textColor
property actually changes the text color, but only if the Foldout is closed. I can't find a way to change the Foldout color when it's open.
Any idea?
Thanks & a nice day :)
Daniele
Answer by Bunny83 · Feb 20, 2011 at 04:01 PM
Had the similar problem some weeks ago. I used EditorGUIUtility.LookLikeInspector()
and it works as expected. Even the function changes: Now you can click on the text to toggle. The control-style foldout ( EditorGUIUtility.LookLikeControls()
) only toggles when you click on the small arrow.
Don't know if there is a way to change the color of the control-style foldout... haven't found one yet.
Thanks a lot Bunny, this is very useful :) Though actually, I do need the LookLikeControls() look :/ I suppose this is a Unity bug then.
P.S. though I'll definitely try to switch to LookLikeInspector(): what you told me about the text activating the toggle is much nicer than having to click the arrow :)
Sure ;) i just switch temporally and switch back right after drawing the foldout.
Oh, didn't realize it could be done (I thought it was kind of a global setting)! Thanks I'll definitely do it :)
Looks like there are no other solutions :P Checking yours as the "right hack" :)
Answer by jite · Sep 27, 2012 at 06:00 AM
This works fine in any mode:
GUIStyle myFoldoutStyle = new GUIStyle(EditorStyles.foldout);
Color myStyleColor = Color.blue;
myFoldoutStyle.fontStyle = FontStyle.Bold;
myFoldoutStyle.normal.textColor = myStyleColor;
myFoldoutStyle.onNormal.textColor = myStyleColor;
myFoldoutStyle.hover.textColor = myStyleColor;
myFoldoutStyle.onHover.textColor = myStyleColor;
myFoldoutStyle.focused.textColor = myStyleColor;
myFoldoutStyle.onFocused.textColor = myStyleColor;
myFoldoutStyle.active.textColor = myStyleColor;
myFoldoutStyle.onActive.textColor = myStyleColor;
Answer by Demigiant · Feb 21, 2011 at 10:45 AM
Not really an answer, but some data based on Bunny83's hack (while waiting for an eventual non-hack solution - if it exists :P).
The unstylable Foldout issue happens if you're using the EditorGUIUtility.LookLikeControls()
mode
Otherwise, it's still a mess! Applying EditorGUIUtility.LookLikeInspector()
just before the Foldout creation (and reverting to LookLikeControls()
immediately after) allows to style the Foldout, though not that easily. Here is a list of render settings for each Foldout state (the unlisted ones have no use):
- normal: Foldout closed and unfocused
- active: on Foldout click when closed
- onNormal: Foldout open and unfocused
- onActive: on Foldout click when open
- onFocused: Foldout open and focused (attention here: needs onActive and focused to be set/changed, otherwise it doesn't work!)
- focused: Foldout closed and focused
I tested this not by creating an entirely new GUIStyle, but by cloning the default with foldoutStyle = new GUIStyle(EditorStyles.foldout)