question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Request] Support Enum Flags

See original GitHub issue

For 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcusx2commented, Mar 18, 2021

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

0reactions
dbrizovcommented, May 3, 2021

Done in 7a2d8e17a2a979a484a32aa9d3bc17daed0a4e12

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found