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

[Feature Request] - Enum Categorization #96

Open
zRevenger opened this issue Dec 21, 2023 · 4 comments
Open

[Feature Request] - Enum Categorization #96

zRevenger opened this issue Dec 21, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@zRevenger
Copy link

Hi, I'm back annoying you with yet another feature request that might be cool. This time I'm talking about enum categorization, it would be useful to have a way to assign categories/groups to enum values and be able to fold them and/or filter them in the inspector, would be useful to have more order, especially if enums start having a lot of options.

@arimger arimger self-assigned this Dec 23, 2023
@arimger arimger added the enhancement New feature or request label Dec 23, 2023
@arimger
Copy link
Owner

arimger commented Dec 23, 2023

Hi!

Can you provide a use-case for me? How do you think this feature should work with an example enum, etc.
In the meantime I suggest using 'SearchableEnumAttrbiute', it's a perfect way to pick enums from larger lists.

@zRevenger
Copy link
Author

Well, the thing isn't just to search in bigger enums, but categorize them, or tag them for specific selection

Example enum:

enum ChoosableClass
{
    [EnumCategory("Ranged")] Gunner,
    [EnumCategory("Ranged")] Archer,
    [EnumCategory("Ranged")] Mage,
    [EnumCategory("Melee")] Warrior,
    [EnumCategory("Melee")] Berserker,
    [EnumCategory("Melee")] Tank
}

Example filtering:
[FilteredEnum("Melee")] ChoosableClass meleeClass;

This is just a simple case, but as you can see everything fits under the ChoosableClass enum, but some things have different categories, and maybe I wanna be able to choose in some cases between just specific categories of that single enum, hope this makes more sense and is more specific

@arimger
Copy link
Owner

arimger commented Dec 26, 2023

Yes, I can implement something similar.

Alternatively and something more lightweight you can use Flag-based "categories" like this:

[System.Flags]
public enum ChoosableClass
{
    Nothing = 0,

    Gunner = 1,
    Archer = 2,
    Mage = 4,
    Warrior = 8,
    Berserker = 16,
    Tank = 32,

    Ranged = Gunner | Archer | Mage,
    Melee =  Warrior | Berserker | Tank,

    Everything = ~0
}

...

ChoosableClass.Ranged.HasFlag(pickedClass);

I can implement drawer that allows only enum values that match provided flag.

@zRevenger
Copy link
Author

So basically "ranged" is never picked but is instead used to check if what I selected is within "ranged", correct?
If so I'll see if this is something that could work for my use case

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

No branches or pull requests

2 participants