using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomPropertyDrawer(typeof(EnumFlags))]
public class EnumFlagsEditor : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames);
}
using System.Collections;
using UnityEditor;
[CustomPropertyDrawer(typeof(EnumFlags))]
public class EnumFlagsEditor : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames);
}
}
using UnityEngine;
using System.Collections;
public class EnumFlags : PropertyAttribute
{
}
using UnityEngine;
using System.Collections;
public class EnumTest : MonoBehaviour
{
public enum Enemy { 暗夜精灵,亡灵,兽人,人类}
[EnumFlags]
public Enemy enemy;
}
把EnumTest.cs脚本挂在GameObject上
本文展示了如何在Unity中使用自定义属性和自定义编辑器来处理枚举位字段,包括实现枚举位的可视化编辑器。通过创建一个名为EnumFlags的属性和一个名为EnumFlagsEditor的自定义属性编辑器,可以更方便地管理和修改游戏中角色的多种状态。示例脚本应用于一个名为EnumTest的MonoBehaviour类,展示了如何将自定义属性应用到枚举类型上。
990

被折叠的 条评论
为什么被折叠?



