打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Unity扩展让枚举视图中变成多选框

标签:

如图:

定义属性描述特性(因为没有描述的数据,让绘制类去绘制所以为空)

using UnityEngine;using System.Collections;public class EnumFlagsAttribute : PropertyAttribute {}

自定义属性绘制类:

using UnityEngine;using System.Collections;using UnityEditor;[CustomPropertyDrawer(typeof(EnumFlagsAttribute))]public class EnumFlagsAttributeDrawer : PropertyDrawer {    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)    {        /*         * 绘制多值枚举选择框,0 全部不选, -1 全部选中, 其他是枚举之和         * 枚举值 = 当前下标值 ^ 2         * 默认[0^2 = 1 , 1 ^2 = 2,  4, 16 , .....]         */        property.intValue = EditorGUI.MaskField(position, label, property.intValue                                                , property.enumNames);        Debug.Log("图层的值:" + property.intValue);    }}

组件:

using UnityEngine;using System.Collections;public enum LayerMeskEnum {    Layer1,    Layer2,    Layer3,    Layer4,}public class MyCompoment : MonoBehaviour {    [EnumFlagsAttribute]    public LayerMeskEnum layer;}

项目结构:

Unity扩展让枚举视图中变成多选框

标签:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
GetAxis
Unity3D架构之第一弹 《善用接口》
读取Txt和实例化Txt内信息物体
C# 栈—— 入栈 出栈 获取栈顶元素 遍历 清空 数量_c#清空栈
在.net中读写XML方法的总结
V5.8类的小结
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服