Reputation: 43
Well i have this Enums to be set on the inspector but i want to limite which enum will show depending on the Main Enum Selected to avoid using different enum than the desired
public MainSortEnum Sort;
public SecondaryTypeEnum1 Type1;
public SecondaryTypeEnum2 Type2;
public SecondaryTypeEnum3 Type3;
And the Enums
public enum MainSortEnum
{
First,
Second,
Thirth,
}
public enum SecondaryTypeEnum1
{
FirstType,
SecondType,
ThirthType,
}
public enum SecondaryTypeEnum2
{
FirstType,
SecondType,
ThirthType,
}
public enum SecondaryTypeEnum3
{
FirstType,
SecondType,
ThirthType,
}
So i just want to Be able on the inspector on this script to select the desired enum based on the MainSortEnum, is this posible?
Upvotes: 4
Views: 2858
Reputation: 2303
You will need to create a custom inspector for the class that these enums
are in.
For instance, we will call such a class MyClass
:
... //other namespaces
using UnityEditor;
[CustomEditor(typeof(MyClass))]
public class MyClassEditor : Editor {
MyClass myClass;
void OnEnable() {
myClass = (MyClass)target;
}
public override void OnInspectorGUI() {
myClass.Sort = EditorGUILayout.EnumPopup("Sort", myClass.Sort);
if (myClass.Sort == MainSortEnum.First)
myClass.Type1 = EditorGUILayout.EnumPopup("Type 1", myClass.Type1);
else if (myClass.Sort == MainSortEnum.Second)
myClass.Type2 = EditorGUILayout.EnumPopup("Type 2", myClass.Type2);
else
myClass.Type3 = EditorGUILayout.EnumPopup("Type 3", myClass.Type3);
}
}
Upvotes: 1
Reputation: 1748
The easiest approach is to have multiple GameObjects
(3 in your case) and switch the gameObject.SetActive(true/false)
based of the user input.
Upvotes: 0