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:

  1. how to use the custom editor.
  2. what aspects go under the creation of a new window or simply changing the inspector.
  3. how to create an attribute.
  4. whether or not the enum needs to be serialized or the variable of that type.

any help would be greatly appreciated

I guess instead of EnumPopup you might just want to use EnumMaskField :wink:

Keep in mind that you have to cast the return type into your enum type since C# uses strong types.

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