方法一:[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下是不能打包的,所以第三種方法只適合在開發(fā)中方便我們配置,在打包的時候需要刪除或修改。