https://www.jianshu.com/p/e4f4faeb8455
using UnityEngine;
using System;
using UnityEditor;
[AttributeUsage(AttributeTargets.Field)]
public class FieldLabelAttribute : PropertyAttribute
{
public string label;
public FieldLabelAttribute(string label)
{
this.label = label;
}
}
[CustomPropertyDrawer(typeof(FieldLabelAttribute))]
public class FieldLabelDrawer : PropertyDrawer
{
private FieldLabelAttribute FLAttribute
{
get { return (FieldLabelAttribute)attribute; }
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, new GUIContent(FLAttribute.label), true);
}
}
这篇博客介绍了如何使用Unity引擎中的FieldLabelAttribute和FieldLabelDrawer来创建自定义字段标签,提升UI的可读性和开发者体验。通过FieldLabelAttribute,开发者可以为字段添加特定的标签,FieldLabelDrawer则负责在编辑器中显示这些标签。
12万+

被折叠的 条评论
为什么被折叠?



