Unity3d枚举多选

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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章