How to make large dropdown menu for variables?

I know it is possible to make a dropdown filter (where depending on which dropdown item is selected, different variables are shown or hidden) but I want something like what cinemachine does:
like this

How might I do this in a MonoBehaviour?

Hi! This is possible with custom editors! Basically, you can check the value of some enum and only render the other fields depending on the value of the enum.

Here is an example script:

using UnityEngine;

public class MyScript : MonoBehaviour
{
    public MyOptions Options;
    public int MyInt;
    public bool MyBool;
}

public enum MyOptions
{
    Int,
    Bool,
    IntAndBool,
}

And here is the custom editor for that script:

using UnityEditor;

[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor
{
    public override void OnInspectorGUI()
    {
        SerializedProperty enumProperty = serializedObject.FindProperty(nameof(MyScript.Options));
        SerializedProperty boolProperty = serializedObject.FindProperty(nameof(MyScript.MyBool));
        SerializedProperty intProperty = serializedObject.FindProperty(nameof(MyScript.MyInt));

        EditorGUILayout.PropertyField(enumProperty);
        MyOptions displayOption = (MyOptions)enumProperty.enumValueIndex;

        if (displayOption == MyOptions.Bool || displayOption == MyOptions.IntAndBool)
        {
            EditorGUILayout.PropertyField(boolProperty);
        }
        if (displayOption == MyOptions.Int || displayOption == MyOptions.IntAndBool)
        {
            EditorGUILayout.PropertyField(intProperty);
        }

        serializedObject.ApplyModifiedProperties();
    }
}

You should put your custom editors in a folder named ‘Editor’ otherwise unity won’t build. But otherwise, there shouldn’t be any problem with this approach!

Of course, this is only scratching the surface of custom editors, as you can add buttons, info boxes, and tons of other unique effects. They are great for adding that extra little touch to your scripts!

Hope this helps :smiley: