[Request] Support Enum Flags
See original GitHub issueFor the ShowIf/HideIf attribute, please allow Enum Flags as input. For example:
[Flags] public enum Pets {
None = 0,
Dog = 1,
Cat = 2,
Bird = 4,
Rabbit = 8,
Other = 16
}
private Pets pets = Pets.Dog | Pets.Cat;
[ShowIfEnum("pets", Pets.Dog)]
public int myint;//will show if pets has Dog flag
Please see https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/ for reference
Here’s the code snippet that does the trick with this other library:
// get the value & compare based on types
switch (comparedField.type)
{ // Possible extend cases to support your own type
case "bool":
return comparedField.boolValue.Equals(drawIf.comparedValue);
case "Enum":
return (comparedField.intValue & (int)drawIf.comparedValue) == (int)drawIf.comparedValue;
default:
Debug.LogError("Error: " + comparedField.type + " is not supported of " + path);
return true;
}
Please note that the code above for enum works if it’s a normal enum as well. So if it’s a flag enum or normal enum it will work.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
c# - What to do when bit mask (flags) enum gets too large
I have a very large set of permissions in my application that I represent with a Flags enumeration. It is quickly approaching the...
Read more >Go: What is Flags Enum and How to Implement It
Flags Enum In Go · Has(flags int, value int) : This function checks if a specific value is set within the flags enum,...
Read more >Request: Enhanced enum & flags support · Issue #20
Bitmasked enum (flag) values as arguments without custom type converters or ILists; ArgDescription attributes on enum values, which appear in ...
Read more >enums usage of [Flags] attribute : r/csharp
The Flags attribute marks the enum as a bitfield enum. A bitfield enum is a type of enum where each member represents a...
Read more >FlagsAttribute Class (System)
Use the FlagsAttribute custom attribute for an enumeration only if a bitwise operation (AND, OR, EXCLUSIVE OR) is to be performed on a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know it can be done with functions, but there are so many fields in the enum that it’s just not practical. Please support enum flags like you support bool
Done in 7a2d8e17a2a979a484a32aa9d3bc17daed0a4e12