arimger / Unity-Editor-Toolbox

Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.
MIT License
1.7k stars 125 forks source link

[Feature Request] - Enum Categorization #96

Open zRevenger opened 9 months ago

zRevenger commented 9 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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