PropertyDrawer 自定义属性绘图
来源:互联网 发布:知乎 紫外线消毒 人体 编辑:程序博客网 时间:2024/05/16 07:05
转自:http://www.cnblogs.com/martianzone/p/4867982.html
public class PlayerAttributeExample : MonoBehaviour{ //无滑块的属性 public int VIPLevel = 0; //特性限定,有滑块 [Range(0, 10)] public int SliderVIPLevel = 0;}
Range特性的方法实现:
using UnityEngine;using System.Collections;//特性的定义要继承自PropertyAttributepublic class MyRangeAttribute : PropertyAttribute{ public float Min;//最小值 public float Max;//最大值 public MyRangeAttribute(float min, float max) { this.Min = min; this.Max = max; }}
using UnityEngine;using System.Collections;using UnityEditor;//继承PropertyDrawer, 必须放入Editor文件夹下[CustomPropertyDrawer(typeof(MyRangeAttribute))]public class MyRangeAttributeDrawer : PropertyDrawer{ //重载OnGUI方法 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { MyRangeAttribute myRange = attribute as MyRangeAttribute; if (property.propertyType == SerializedPropertyType.Integer) { EditorGUI.IntSlider(position, property, (int)myRange.Min, (int)myRange.Max, label); } else if (property.propertyType == SerializedPropertyType.Float) { EditorGUI.Slider(position, property, myRange.Min, myRange.Max, label); } else { } }}
2.绘制多选
public enum SomeFood { 汉堡 = 0, 鸡肉卷 = 1, 薯条 = 3, } //只能单选 public SomeFood MyLoveFood; //多选特性 [EnumListAttribute] public SomeFood MyLoveFoodList;
using UnityEngine;using System.Collections;public class EnumListAttribute : PropertyAttribute{}
using UnityEngine;using System.Collections;using UnityEditor;[CustomPropertyDrawer(typeof(EnumListAttribute))]public class EnumListAttributeDrawer : PropertyDrawer{ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames); }}
0 0
- PropertyDrawer 自定义属性绘图
- PropertyDrawer
- 自定义绘图
- 使用 PropertyAttribute和PropertyDrawer
- matlab绘图属性
- CGContext一些绘图属性
- 绘图与动画之使用自定义属性与图像掩膜实现灯泡开关动画
- 绘图与动画之使用自定义属性与颜色渐变实现色带加载动画
- Android 绘图进阶(四):自定义View属性(灰常重要)
- 绘图与动画之使用自定义属性与Quartz实现扇形加载动画
- Android绘图机制(一)——自定义View的基础属性和方法
- Android绘图机制(一)——自定义View的基础属性和方法
- 开发自定义绘图控件
- android 绘图、自定义组件
- UIView自定义绘图
- 用户可视化自定义绘图
- CALayer自定义绘图
- 自定义路径绘图实例
- hdu3790最短路径问题Dijkstra(迪杰斯特拉)
- ZCMU—J
- SpringMVC返回json数据的三种方式
- Java代理机制
- C++STL
- PropertyDrawer 自定义属性绘图
- Android初识(1)
- c 程序设计语言 1-9
- TCP&UDP的区别
- java读取隐藏文件的问题
- Fragment篇——FragmentManager分析及用例
- Java static
- API总结
- 腾讯笔试:格林码+map