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