方法一:[Tooltip("玩家名字")]


方法二:[Header("玩家名字")]


方法三:自定义


脚本如下:

代码直接粘贴上来(排版问题 有可能会乱)
using System;
using UnityEditor;
using UnityEngine;
[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);
}
}
注意:第三种方法的脚本是引用UnityEditor的,引用UnityEditor的脚本不放在Editor下是不能打包的,所以第三种方法只适合在开发中方便我们配置,在打包的时候需要删除或修改。
网友评论