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
{
[System.Serializable]
public class Data
{
string name;
float someValue;
}
[SerializeField]
Data myData1;
[SerializeField]
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.
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 );
EditorGUILayout.Separator();
switch (p_workingMode) {
case 0:
TerrainTool();
break;
case 1:
TextureTool();
break;
case 2:
VegetationTool();
break;
}
}
void TerrainTool(){
////your stuff too show
EditorGUILayout.PropertyField( your variable);
if (GUILayout.Button( "Your name of the button" )) {
your void();
}
}