I can’t remember where I got this from, but I have some custom foldout code for editor windows, which works well, but I tried to put it into a custom inspector, and I can’t toggle it, it is locked to it’s default assigned boolean.
What is wrong with this and why does it work in editor window but not in custom inspector?
public static bool Foldout(string title, bool display)
{
var style = new GUIStyle("ShurikenModuleTitle");
style.font = new GUIStyle(EditorStyles.label).font;
style.border = new RectOffset(15, 7, 4, 4);
style.fixedHeight = 22;
style.contentOffset = new Vector2(20f, -2f);
var rect = GUILayoutUtility.GetRect(16f, 22f, style);
GUI.Box(rect, title, style);
var e = Event.current;
var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
if (e.type == EventType.Repaint)
{
EditorStyles.foldout.Draw(toggleRect, false, false, display, false);
}
if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
{
display = !display;
e.Use();
}
return display;
}
public override void OnInspectorGUI()
{
bool ControlSettingsFoldout = true;
ControlSettingsFoldout = Foldout("Control Settings", ControlSettingsFoldout);
if(ControlSettingsFoldout)
{
scriptTarget.active = EditorGUILayout.Toggle("Active", scriptTarget.active);
}
}