Unity-Editor-Toolbox icon indicating copy to clipboard operation
Unity-Editor-Toolbox copied to clipboard

[Feature Request] - Enum Categorization

Open zRevenger opened this issue 1 year ago • 4 comments

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.

zRevenger avatar Dec 21 '23 14:12 zRevenger

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.

arimger avatar Dec 23 '23 21:12 arimger

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

zRevenger avatar Dec 24 '23 00:12 zRevenger

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.

arimger avatar Dec 26 '23 22:12 arimger

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

zRevenger avatar Dec 27 '23 18:12 zRevenger