So like many before me, I wanted enum flags available in the editor. The best solutions I found were using a custom Attribute and PropertyDrawer to make it look like similar to the LayerMask dropdown. While that’s neat, it comes with the disadvantage that you have no real overview once multiple flags are set. You need to open the dropdown to see the actual state.
That didn’t work for me, so I built a solution using Toggle Buttons:
Hi @Democide
I just tried popping this in, and I get a single row of absolutelly tiny buttons. Is there a trick to getting 3 nicely formatted rows as you have in the gif above? Thanks!
These are three separate enums. The issue is, that you have an enum with a lot of options. There’s currently no code that detects this and does any linebreaks. I didn’t need it and didn’t really want to bother. It’s not terribly difficult but I just was done with it at that point.
If you do upgrade it to contain that functionality, let me know though. I’d be happy to update the script.
This is fantastic, exactly what I was looking for. I know that it has been a while but. Do you have any idea why I am getting a type is not a enum value in the SetDimensions at these two lines?
public enum EPlayMode { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z }
Here is where I am trying to access the data.
public class Object : MonoBehaviour
{
[EnumFlag] public EPlayMode test;
private void Update() {
Debug.Log("a" + !test.Equals(EPlayMode.FirstOnly));
Debug.Log("b" + !test.Equals(0));
}
}
Eventually, I would like to write if statements that check what values are selected and do something specific depending on what is selected. What I am want to do with this is have a bunch of different ambient sounds that I can select on an object. If crows are selected then you will hear crows, if crows and windy trees are selected then you will hear crows and trees blowing in the wind. This may not be the best way of doing this architecturally but its the idea that is in my head.
Whatever the problem is in the original post, this is (presumably) not going to fix it, because a bit field enumeration behaves differently than a constant value enumeration. You an find more about this in the official Microsoft Docs, under FlagsAttribute Class. There are also examples and guidelines on how to use this attribute.
EDIT: Looked a bit deeper into the posted code, yes, you are right, they use enumeration as a bit field, so the attribute should be used.
Other than that, it is a great way to achieve OP’s need, in particular this: