EnumSelection shows popups which can select enum class & value.
If you like, please press ⭐ ⭐ ⭐
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.
Download from latest release page.
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.
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
Check stored class is expecting enum.
bool isSampleEnum1 = this.Value.IsEnumClass<Sample>();
bool isSampleEnum2 = this.Value.IsEnumClass(typeof(Sample));
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;
}