工程截图
示例代码
Range1DecoratorDrawer.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
//自定义特性的装饰属性样式
[CustomPropertyDrawer(typeof(Range1Attribute))]
public class Range1DecoratorDrawer : DecoratorDrawer
{
private Texture2D icon;
private Range1Attribute _attribute;
public override void OnGUI(Rect position)
{
_attribute = attribute as Range1Attribute;
if (null == icon)
icon = Resources.Load<Texture2D>("icon");
position.width = 50;
position.height = 50;
GUI.DrawTexture(position, icon);
}
public override float GetHeight()
{
if(null == _attribute)
return 0;
return base.GetHeight() + _attribute.GetHeight();
}
}
Test.cs
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
[Range1(0.0F, 10.0F)]
public float myFloat = 0.0F;
}
效果