- Home /
Question by
jetous · Aug 07, 2018 at 09:10 PM ·
c#editor-scriptingenum
Limiting options in Unity Editor enum popup box based on prior selection
I'm making a Unity Editor script that builds itself out as the user selections options. What I'm having trouble with is figuring out how to limit the options presented so that incompatible types aren't chosen. My scripts are:
public class Example: MonoBehaviour {
public enum ExampleType { A, B, C }
public enum ExampleSubType { 1, 2, 3 }
}
public class ExampleEditor : Editor {
SerializedProperty exampleType;
SerializedProperty exampleSubType;
private void OnEnable() {
exampleType = serializedObject.FindProperty("exampleType");
exampleSubType = serializedObject.FindProperty("exampleSubType");
}
private void OnInspectorGUI() {
EditorGUILayout.PropertyField(exampleType);
Example.ExampleType eT = (Example.ExampleType)exampleType.enumValueIndex;
Example.ExampleSubType eST = (Example.ExampleSubType)exampleSubType.enumValueIndex;
switch (et) {
case Example.ExampleType.A :
switch (eST) {
EditorGUILayout.PropertyField(exampleSubType);
case Example.ExampleSubType.1 :
// Stuff that applies to SubType.1
break;
case Example.ExampleSubType.3 :
// Stuff that applies to SubType.3
break;
}
break;
case Example.ExampleType.B :
// Same setup as A, but with eST 2 and 3
break;
case Example.ExampleType.C :
// Same setup as A, but with eST 1 and 2
break;
}
}
So in this editor script, I want to make it that if the user selects ExampleType.A, then ExampleSubType.2 does not show up in the ExampleSubType popup window. How do I go about culling invalid options?
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Working with Unity Editor 1 Answer
How to play mecanim animations in Editor mode? 2 Answers
ScriptableObject Drop-Down Menu with added variables? 1 Answer