(LabelTextAttribute)属性中文标签

LabelTextAttribute

功能:
用于更改属性的标签。
如果你想要一个不同于标签名称的标签,可以使用它。

简单的实现:

using UnityEngine;
#if UNITY_EDITER
using UnityEditor;
#endif

public class LabelTextAttribute : PropertyAttribute
{
    public string Label { get; private set; }

    public LabelTextAttribute(string label)
    {
        this.Label = label;
    }
}

#if UNITY_EDITER
[CustomPropertyDrawer(typeof(LabelTextAttribute),false)]
public class LabelDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label.text = (attribute as LabelTextAttribute)?.Label;
        EditorGUI.PropertyField(position, property, label);
    }
}
#endif

使用:

[LabelText("A的标签")]
public int a;

效果
这里写图片描述


喜欢这些小知识的请滚关注我,我会不定时更新。

猜你喜欢

转载自blog.csdn.net/qq_35443068/article/details/79248372
今日推荐