- Home /
Exposing Enums in Custom Inspector
I'm writing a custom inspector, and I'm trying to display enums the way Unity does naturally (displaying them and of course, changing them). After playing around with it my self, I managed to display the element's names into a popup list, but selecting the values of the enums via popup list doesn't have any actual effect.
Here is what I have so far:
var battleState : SerializedProperty;
var bsIndex : int;
var bsOptions : String[];
var infliction : SerializedProperty;
var iIndex : int;
var iOptions : String[];
var behavior : SerializedProperty;
var bIndex : int;
var bOptions : String[];
function ShowStates()
{
//battleState.Enum = EditorGUILayout.EnumPopup("Battle State:", battleState);
bsOptions = battleState.enumNames;
bsIndex = EditorGUILayout.Popup(bsIndex, bsOptions);
bOptions = behavior.enumNames;
bIndex = EditorGUILayout.Popup(bIndex, bOptions);
iOptions = infliction.enumNames;
iIndex = EditorGUILayout.Popup(iIndex, iOptions);
}
Is there a reason why you don't use the EditorGUILayout.EnumPopup?
Yeah, I wasn't sure how to use it. When I serialized any of the enums, I'm not sure how to grab the enum property from them.
Hmm, just realized you used a SerializedProperty. I guess it's the best way then. EnumPopup works best when you have a variable of a certain enum type.
Anyway, it's solved ;)
Answer by SrBilyon · Jul 03, 2012 at 11:11 AM
Silly me! I solved it. For anyone in the future, this is what I did:
I took my serialized enum, and set the "enumValueIndex" equal to the index int I declared in my editor script.
Example:
battleState.enumValueIndex = bsIndex;
Your answer
Follow this Question
Related Questions
How to change inspector with non-Monobehaviour objects ? 1 Answer
Custom Inspector Layer Mask variable 2 Answers
Creating vertical space for EditorGUI 2 Answers
Insert new custom class element with _default_ values to a SerializedProperty array? 1 Answer
DropDownList with string array in Editor Inspector 5 Answers