Unity 在Inspector面板上實現多選枚舉


//EnumFlags.cs
using UnityEngine;
///
<summary> ///定義多選屬性 ///</summary> public class EnumFlags : PropertyAttribute{}



//EnumFlagsDrawer.cs
using UnityEngine;
using UnityEditor;
///<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;
 
 
        

效果如圖

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM