Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Support Enum Flags #217

Closed
marcusx2 opened this issue Mar 18, 2021 · 6 comments
Closed

[Request] Support Enum Flags #217

marcusx2 opened this issue Mar 18, 2021 · 6 comments

Comments

@marcusx2
Copy link

marcusx2 commented Mar 18, 2021

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.

@marcusx2
Copy link
Author

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

@dbrizov
Copy link
Owner

dbrizov commented Apr 24, 2021

Duplicates #167

@dbrizov dbrizov closed this as completed Apr 24, 2021
@marcusx2
Copy link
Author

@dbrizov Does the new update support enum flags, or just normal enum?

@dbrizov
Copy link
Owner

dbrizov commented Apr 27, 2021

Oh, only enum. I am reopening it :D

@dbrizov dbrizov reopened this Apr 27, 2021
@marcusx2
Copy link
Author

marcusx2 commented Apr 27, 2021

@dbrizov Thanks haha. It would be great if enum flags were supported as well. Please see the code snippet I posted, the case enum. It handles enum flags as well so I can select multiple items on a dropdown.

@dbrizov
Copy link
Owner

dbrizov commented May 3, 2021

Done in 7a2d8e1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants