1、多选
public class EnumFlags : PropertyAttribute { }
[CustomPropertyDrawer(typeof(EnumFlags))]
public class EnumFlagsAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames);
}
}
2、选择判断
private bool IsSelectEventType(EvidenceAttribute _eventType)
{
// 将枚举值转换为int 类型, 1 左移
int index = 1 << (int)_eventType;
// 获取所有选中的枚举值
int eventTypeResult = (int)evidenceAttribute;
// 按位 与
if ((eventTypeResult & index) == index)
{
return true;
}
return false;
}
3、遍历
foreach (EvidenceAttribute item in Enum.GetValues(typeof(EvidenceAttribute)))
{
if (IsSelectEventType(item))
{
//DoSomesing
}
}