Unity3d枚举多选
默认的enum枚举在监视窗口下是只有单选的,下面只需要添加简单的脚本,便能实现多选
新建C#脚本EnumFlags和EnumFlagsDrawer
打开EnumFlags脚本
添加如下代码
using UnityEngine;
public class EnumFlags : PropertyAttribute { }
打开EnumFlagsDrawer脚本,添加如下代码
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(EnumFlagsAttribute))]
public class EnumFlagsAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
property.intValue = EditorGUI.MaskField(position, label, property.intValue
, property.enumNames);
}
}
使用如下
public enum solt
{
solt1,
solt2,
solt3
}
[EnumFlags]
public solt example = solt.solt1;