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;
效果
喜欢这些小知识的请滚关注我,我会不定时更新。