public class PlayerAttributeExample : MonoBehaviour
{
//无滑块的属性
public int VIPLevel = ; //特性限定,有滑块
[Range(, )]
public int SliderVIPLevel = ;
}

Range特性的方法实现:

using UnityEngine;
using System.Collections; //特性的定义要继承自PropertyAttribute
public 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
{
汉堡 = ,
鸡肉卷 = ,
薯条 = ,
}
//只能单选
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);
}
}

PropertyDrawer 自定义属性绘图的更多相关文章

  1. Layer中自定义属性的动画

    转载自:http://blog.jobbole.com/69211/ 默认情况下,CALayer 及其子类的绝大部分标准属性都可以执行动画,无论是添加一个 CAAnimation 到 Layer(显式 ...

  2. Layer 中自定义属性的动画

    原文:http://objccn.io/issue-12-2/ Layer 中自定义属性的动画     默认情况下,CALayer 及其子类的绝大部分标准属性都可以执行动画,无论是添加一个 CAAni ...

  3. Canvas绘图之平移translate、旋转rotate、缩放scale

    画布操作介绍 画布绘图的环境通过translate(),scale(),rotate(), setTransform()和transform()来改变,它们会对画布的变换矩阵产生影响. 函数 方法 描 ...

  4. 用html5的canvas和JavaScript创建一个绘图程序

    本文将引导你使用canvas和JavaScript创建一个简单的绘图程序. 创建canvas元素 首先准备容器Canvas元素,接下来所有的事情都会在JavaScript里面. <canvas ...

  5. echarts+php+mysql 绘图实例

    最近在学习php+mysql,因为之前画图表都是直接在echart的实例demo中修改数据,便想着两相结合练习一下,通过ajax调用后台数据画图表. 我使用的是echart3,相比较第二版,echar ...

  6. html5 canvas常用api总结(二)--绘图API

    canvas可以绘制出很多奇妙的样式和美丽的效果,通过几个简单的api就可以在画布上呈现出千变万化的效果,还可以制作网页游戏,接下来就总结一下和绘图有关的API. 绘画的时候canvas相当于画布,而 ...

  7. HTML5_04之SVG绘图

    1.关于Canvas绘制图像: 问题:需要绘制多张图片时,必须等待所有图片加载完成才能开始绘制:而每张图片都是异步请求,彼此没有先后顺序,哪一张先加载完成完全无法预测: 方案: var progres ...

  8. Android自定义控件之自定义属性

    前言: 上篇介绍了自定义控件的基本要求以及绘制的基本原理,本篇文章主要介绍如何给自定义控件自定义一些属性.本篇文章将继续以上篇文章自定义圆形百分比为例进行讲解.有关原理知识请参考Android自定义控 ...

  9. HTML5 学习总结(四)——canvas绘图、WebGL、SVG

    一.Canvas canvas是HTML5中新增一个HTML5标签与操作canvas的javascript API,它可以实现在网页中完成动态的2D与3D图像技术.<canvas> 标记和 ...

随机推荐

  1. Solr中Schema.xml中文版

    <?xml version="1.0" encoding="UTF-8" ?> <!-- Licensed to the Apache Sof ...

  2. itunes connect提交app教程

    .打开itunes connect登陆之后,选择Manage Your Apps,再选Add New App: .填写项目相关信息,不知道怎么填的点击问号查看: Bundle ID Suffix需要和 ...

  3. html+css--水平居中总结(不定宽块状元素方法)(一)

    来源:http://www.imooc.com/code/6363 在实际工作中我们会遇到需要为“不定宽度的块状元素”设置居中,比如网页上的分页导航,因为分页的数量是不确定的,所以我们不能通过设置宽度 ...

  4. asp.net Calendar 日历控件用法

    asp.net Calendar 是微软自带的一款日历控件,除了简单显示日期时间外, 还可以绑定一些需要的事件. Calendar_DayRender 事件,是在加载都去时间日期时候的方法,用此方法可 ...

  5. Android锁屏软件

    需求描述:锁屏软件就是点击应用然后直接锁屏,不会弹出任何界面 设计思路:应用启动以后通过getSystemService获取系统的服务,调用安卓系统的DevicePolicyManager和Compo ...

  6. 宽度的100%和auto的区别

    前段时间做项目,发现分不清width设为100%和auto的区别,实在是太水了,就查了点资料,做个总结,有不对的地方欢迎大家指出. width:auto 块级元素默认的宽度值.看一下MDN上的解释:T ...

  7. Warning: session_start() [function.session-start]: Cannot send session cookie解决办法

    在很多时间使用了session就会出来如下提示了, Warning: session_start() [function.session-start]: Cannot send session coo ...

  8. 【学习笔记】【C语言】位运算

    1. & 按位与 1> 功能 只有对应的两个二进位均为1时,结果位才为1,否则为0. 2> 举例: 比如9&5,其实就是1001&101=1,因此9&5=1 ...

  9. Chrome系列 Failed to load resource: net::ERR_CACHE_MISS

    在IE/FF下没有该错误提示,但在Chrome下命令行出现如下错误信息: Failed to load resource: net::ERR_CACHE_MISS 该问题是Chrome浏览器开发工具的 ...

  10. 基于python yield机制的异步操作同步化编程模型

    又一个milestone即将结束,有了些许的时间总结研发过程中的点滴心得,今天总结下如何在编写python代码时对异步操作进行同步化模拟,从而提高代码的可读性和可扩展性. 游戏引擎一般都采用分布式框架 ...