- Home /
Flagged Enum representation in Inspector
I am curious to know. I have looked into making serializable objects and fields and it loks like the only thing stopping someone from making a enum with flags (like layermasks) is calculating the enums fields from an int.
so if someone could help me write an editor script in C# to display an enum and a way to get a function to run between the enum and the inspector. I'd be able to put together something that does just that.
things i don't quite know:
how to use the custom editor.
what aspects go under the creation of a new window or simply changing the inspector.
how to create an attribute.
whether or not the enum needs to be serialized or the variable of that type.
any help would be greatly appreciated
Answer by Bunny83 · Jan 28, 2013 at 02:07 AM
I guess instead of EnumPopup you might just want to use EnumMaskField ;)
Keep in mind that you have to cast the return type into your enum type since C# uses strong types.
edit
EnumMaskField of course is also available without layouting, but in the inspector you probably want to use GUILayout.
There's also a general MaskField but the EnumMaskField is actually more powerful since you can even specify combined items:
public enum ETestEnum
{
None = 0, // 0000
Left = 1, // 0001
Center = 2, // 0010
Right = 4, // 0100
LeftAndRight = 5, // 0101
CenterLeft = 3, // 0011
CenterRight = 6, // 0110
All = 7, // 0111
}
well that's part of what i need (can't believe its right there so easy) but how exactly is that editor used (since all examples are in java script its a bit hard to read)
and there is also the placement. do you have to serialize? and if so... what do you serialize?
What placement? Do you talk about a custom editor aka inspector or about an EditorWindow? Enums are serialized automatically by Unity, so just change the value on a script instance and Unity will take care of the rest. If you want to implement a multiple object editor you have to use the serializedObject property of your Editor.
I don't have the time to post a whole editor example. I need some sleep ;)
thank you for the quick reply, I'll figure it out from here thanks have a goodnight :)