- Home /
Custom inspector - disabling specific controls.
I know there is EditorGUILayout.BeginToggleGroup () - but what I want is the reverse kind of it. When I turn on a toggle and some other controls turn to grey. Is there a way for it?
Comment
Answer by numberkruncher · Jan 18, 2013 at 03:48 PM
That can be achieved using something like the following:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(SomeBehaviour))]
public class InspectorExample : Editor {
private SerializedProperty specialFeature;
void OnEnable() {
specialFeature = serializedObject.FindProperty("specialFeature");
}
public override void OnInspectorGUI() {
serializedObject.Update();
specialFeature.boolValue = EditorGUILayout.Toggle(specialFeature.boolValue);
GUILayout.Button("Always active");
GUI.enabled = specialFeature.boolValue;
GUILayout.Button("Maybe active");
GUI.enabled = true;
GUILayout.Button("Always active");
serializedObject.ApplyModifiedProperties();
}
}
Warning, not tested, but this should work :-)
What is the advantage here to use a SerializedProperty ins$$anonymous$$d of a regular bool? Isn't the inspector class Instance gonna get destroyed when we select something else anyways?