Skip to content

Instantly share code, notes, and snippets.

@WSWhitehouse
Last active January 22, 2023 02:50
Show Gist options
  • Save WSWhitehouse/371605374bb016195ab727225b599d90 to your computer and use it in GitHub Desktop.
Save WSWhitehouse/371605374bb016195ab727225b599d90 to your computer and use it in GitHub Desktop.
Better EditorFoldout for Unity's Editor! Allows the user to click the foldout text as well as the arrow to toggle the foldout.
// ------------------------------------------ //
// Author : William Whitehouse / WSWhitehouse //
// GitHub : github.com/WSWhitehouse //
// Date : 27/06/2019 //
// ------------------------------------------ //
using UnityEditor;
using UnityEngine;
public static class EditorFoldout
{
public static bool Foldout(bool foldout, GUIContent content, GUIStyle style = null, bool toggleOnLabelClick = true)
{
if (style == null)
style = EditorStyles.foldout;
Rect position = GUILayoutUtility.GetRect(40f, 40f, 16f, 16f, style);
return EditorGUI.Foldout(position, foldout, content, toggleOnLabelClick, style);
}
public static bool Foldout(bool foldout, string content, GUIStyle style = null, bool toggleOnLabelClick = true)
{
return Foldout(foldout, new GUIContent(content), style, toggleOnLabelClick);
}
}
@WSWhitehouse
Copy link
Author

WSWhitehouse commented Jun 27, 2019

Unity's Foldout:
Unity's Foldout

foldoutBool = EditorGUILayout.Foldout(foldoutBool, new GUIContent("Foldout Test"));

New EditorFoldout:
EditorFoldout

foldoutBool = EditorFoldout.Foldout(foldoutBool, new GUIContent("Foldout Test"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment