DecoratorDrawer

作者:追风剑情 发布于:2017-12-25 17:39 分类:Unity3d

工程截图

1111.png

示例代码

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;
}

效果

2222.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号