I have a variable containing some flags and wounder how I'm able to check which flags that are set.
My flags.
[Flags]
public enum Button{
//Can't have more than 30 flags
//If an enum is added or deleted need to change for loop in method AddButton
// Exit flags
Exit = 1 << 0,
Cancel = 1 << 1,
Abort = 1 << 2,
Close = 1 << 3,
//Proced flags
Accept = 1 << 4,
Ok = 1 << 5,
Submit = 1 << 6,
//Question flags
No = 1 << 7,
Yes = 1 << 8,
//Save and load
Save = 1 << 9,
SaveAll = 1 << 10,
SaveNew = 1 << 11,
Open = 1 << 12,
Load = 1 << 12
}
And here are where i check my flags
for (int i = 1; i <= 12; ++i) {
if((buttons & 1 << i) == 1 << i){
}
}
Apparently I can't use this way to check flags.
To be clear I want to know what flags that are set in buttons.
Update: I can't use the Enum.hasFlag() because I making a game in Unity and it uses Mono. Apparently Mono hasn't support for hasFlag yet.