Hello,
I am making a custom editor window for my behavior tree code.
I need help with a way to display leaf node data in my editor.
Most of my leaf nodes will read data internally from a blackboard, but some will have variables that I want to set in my editor.
Currently I am adding my variables to an object array in the node constructor, and then in my editor I am looping through this array and displaying different GUI fields depending on the variable type.
I’m very excited that this is working great for simple types like string, int and float, but I am now stuck on how to deal with more complex types like enums.
Specifically in the switch cases, how can i make a case for “enum”?
Does anyone have suggestions for other ways to deal with node data of different types?
I like my object array approach but would love to hear more suggestions.
Enums are extremely simple! Choose whether you want to serialize them as Strings or ints, then here are all the operations you need to convert to/from string and int.
MyEnum enumVal;
// Get a list of strings to display a dropdown menu:
string[] possibilities = Enum.GetNames(typeof(MyEnum));
// Convert value to and from string:
string stringVal = enumVal.ToString();
MyEnum backToEnum = MyEnum.Parse(stringVal);
// Convert to and from int:
int intVal = (int)enumVal;
MyEnum fromInt = (MyEnum)intVal;