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;