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