Hiding or showing variables in inspector

I would like to ask if there is easy way to hide/show public variables in inspector depending on other variables.



public bool NeverFlees = true;

it would not show these options:

public int Morale = 100;
public int FleesOnMorale = 0;
public int FleesOnHealth = 10;

If there is no easy way of doing this, I think I could do something like this by extending the editor, right?

Unity recently added some attributes to help manage the inspector from inside the behaviour:

The attributes are still very poorly documented though.

As you correctly point out, you can extend the editor and have complete control of what gets shown, and when. For example:

public class MyEditorClass : Editor
    public override void OnInspectorGUI()
        // If we call base the default inspector will get drawn too.
        // Remove this line if you don't want that to happen.

        MyBehaviourClass myBehaviour = target as MyBehaviourClass;

        target.NeverFlees = EditorGUILayout.Toggle("Never Flees", target.NeverFlees);

        if (target.NeverFlees)
            // Draw the optional fields here