Custom Editor foldout doesn't unfold when clicking on name?

Hi everyone, I implemented my custom Unity editor class with a foldout which shows its child variables when clicked. However, in the inspector, it only unfolds when I click on the little triangle: 25028-2.png

Usually, in Unity’s built-in foldouts (for example: Public array variables), clicking on the name automaticallt unfolds it.

Is there any way to get that effect in a custom Unity Editor Script?

Here’s my code so far:

isUnfolded = EditorGUILayout.Foldout (isUnfolded , "My Folder");

if (isUnfolded)
	//My variables...

I don’t know exactly starting with which version this is available, but very handy:

state = EditorGUILayout.Foldout (state, title, true);

or

state = EditorGUILayout.Foldout (state, title, true, EditorStyles.foldout);

Handle the event yourself before EditorGUILayout.Foldout does for you (and Use it! as shown below)

		EditorGUI.BeginChangeCheck ();
		EditorGUILayout.GetControlRect (true, 16f, EditorStyles.foldout);
		Rect foldRect = GUILayoutUtility.GetLastRect ();
		if (Event.current.type == EventType.MouseUp && foldRect.Contains (Event.current.mousePosition)) {
			foldout = !foldout;
			GUI.changed = true;
			Event.current.Use ();
		}
		foldout = EditorGUI.Foldout (foldRect, foldout, "Foldout");
		if (EditorGUI.EndChangeCheck ()) {
			Debug.Log ("fold state updated");
		}

		if (foldout) {
			EditorGUI.indentLevel++;
			EditorGUILayout.LabelField ("I see you");
			EditorGUI.indentLevel--;
		}

I’ve added some extra stuff to mark the foldout as changed, so it’s handled properly…

Actually, there is a parameter to open and close the foldout by clicking on the label.