Making a collapsible menu in the inspector

I noticed some scripts have different options in collapsible menus in the inspector. For example there's a collapsible menu named "Resolution" and when you open it, it shows the properties.

How do they do it?

In c# preferred, but I guess I could possibly convert from js. Thanks

You can use the EditorGUILayout.Foldout control. It is basically just a special toggle control; assign it to a boolean, and if it is true then draw the controls "inside", if it is false then don't.

I’m sure this question is incredibly old but i stumbled upon it while looking for something else.

Based on the comments you need to make a serializable class to contain the data you want to be foldable. So in my FakeDataBehaviour as a monobehaviour, we have a FakeData class that contains something interesting. We define multiple ones inside my class. In the inspector, these will appear as foldable objects for setting the specific values.

for example:

public class FakeDataBehaviour : MonoBehaviour

public class Data
string name;
float someValue;

Data myData1;
Data myData2;
// do more stuff…

I know this is years ago but I think the answer you were looking for was to create a Struct with the vars inside then create a value for it. That gives the fold up menu with the GUI stuff.

private int p_workingMode = 0;

 public  override  void OnInspectorGUI(){
GUIContent[] operationsOptions = new GUIContent[ 3];   //////Number of button in the ToolBar
           operationsOptions[ 0 ] = new GUIContent( "Your Menu Text1",  your Icon1 );
           operationsOptions[ 1 ] = new GUIContent(  "Your Menu Text2",  your Icon2 );
            operationsOptions[2 ] = new GUIContent(  "Your Menu Text3",  your Icon3 );
            p_workingMode = GUILayout.Toolbar( p_workingMode, operationsOptions );
            switch (p_workingMode) {
                case 0:
                case 1:
                case 2:

void TerrainTool(){
////your stuff too show
 EditorGUILayout.PropertyField( your variable);
            if (GUILayout.Button( "Your name of the button" )) {
              your void();