Unity 在Inspector面板上实现多选枚举

using UnityEngine;
using UnityEditor;

///<summary>
///定义多选属性
///</summary>
public class EnumFlags : PropertyAttribute{}

///<summary>
///绘制多选属性
///</summary>
[CustomPropertyDrawer(typeof(EnumFlags))]
public class EnumFlagsDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames);
    }
}


//在需要多选的枚举变量的声明上加上EnumFlags属性标签,如:
[Hear("这里是标题")]
[EnumFlags] //这里是EnumFlags属性标签
public EnumType enumType;
 
 

效果如图

猜你喜欢

转载自www.cnblogs.com/KingR/p/12926851.html