Skip to content

Unity editor extension to select enum class & value 😁

License

Notifications You must be signed in to change notification settings

mattak/EnumSelection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EnumSelection

EnumSelection shows popups which can select enum class & value.

If you like, please press ⭐ ⭐ ⭐

Why?

Unity's default enum popup is easy to use by just declaring simple enum field.

public class SampleBehaviour : MonoBehaviour {
    public SampleEnum Value;
}

public enum SampleEnum {}

But there are some cases which require to handle multiple enum class at one field. For example, implementing skill slots that each of skills is defined by enum.

[EnumSelectionEnable(Category = "Skill")]
public enum AttackSkill
{
    DamageAdd,
    DamageMutiply,
    // ...
}

[EnumSelectionEnable(Category = "Skill")]
public enum DefenceSkill
{
    DamageSubtract,
    // ...
}

EnumSelection handles multiple skill enums at one field.

public class Accessory : MonoBehaviour
{
    [EnumSelectionOption(Category = "Skill")]
    public EnumSelection[] Slot = new EnumSelection[3];

    private void Start()
    {
        foreach(var skill in this.Slot)
        {
            if (skill.IsEnumClass<AttackSkill>())
            {
                var value = skill.GetEnum<AttackSkill>();
                // apply attack skill
            }
            // ...
        }
    }
}

It's very easy to handle multiple enum types and select enum type & value with popups.

multiple skills

Demo

enum selection

Download

Download from latest release page.

Usage

Define enum with EnumSelectionEnable attribute.

[EnumSelectionEnable]
public enum Sample {
    Value1,
    Value2,
}

Refer EnumSelection class on your MonoBehaviour.

public class Demo : MonoBehaviour {
    public EnumSelection Value;
}

That's it!

Now you can select any enums with EnumSelectionEnable attribute.

Parse

There are some methods to parse enum Value.

// EnumSelection Value;
var value1 = this.Value.GetEnum<Sample>();
var value2 = this.Value.GetEnum(typeof(Sample));
var value3 = this.Value.GetEnum(); // automatically parse enum by stored class name & assembly name

Class Check

Check stored class is expecting enum.

bool isSampleEnum1 = this.Value.IsEnumClass<Sample>();
bool isSampleEnum2 = this.Value.IsEnumClass(typeof(Sample));

Categroy

Category restricts enum class on popup menu.

[EnumSelectionEnable(Category = "MyCategory")]
public enum Sample {
    Value1,
    Value2,
}
public class Demo : MonoBehaviour {
    [EnumSelectionOption(Category = "MyCategory")]
    public EnumSelection Value;
}

License

About

Unity editor extension to select enum class & value 😁

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages