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:
[CustomEditor(typeof(MyBehaviourClass))]
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.
base.OnInspectorGUI();
MyBehaviourClass myBehaviour = target as MyBehaviourClass;
target.NeverFlees = EditorGUILayout.Toggle("Never Flees", target.NeverFlees);
if (target.NeverFlees)
{
// Draw the optional fields here
}
}
}
Thanks! And, thank you for the code sample too, I will be able to use it if the documentation isn't very good. (I should really look what could I do by extending the editor, but some why it looked scary for me all this time :D )
Thanks! And, thank you for the code sample too, I will be able to use it if the documentation isn't very good. (I should really look what could I do by extending the editor, but some why it looked scary for me all this time :D )
– edve98The documentation on basic editor stuff isn't too bad, but as things get more complex the documentation becomes less helpful.
– VesuvianPrime