效果
💃想要更炫的效果可以参考官方的文档。
用PropertyDrawer 自定义Inspector 面板显示
https://docs.unity3d.com/ScriptReference/PropertyDrawer.html

代码
新建 FieldNameAttribute.cs 文件
using UnityEngine;
namespace Editor
{
public class FieldNameAttribute : PropertyAttribute
{
public string Name { get; private set; }
public FieldNameAttribute(string name)
{
Name = name;
}
}
}
新建FieldNameAttributeDrawer.cs 文件
using UnityEditor;
using UnityEngine;
namespace Editor
{
[CustomPropertyDrawer(typeof(FieldNameAttribute))]
public class FieldNameAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, new GUIContent((attribute as FieldNameAttribute).Name));
}
}
}
引用
为方便引用,在Editor 文件夹中,新建名为Editor 的Assembly Definition 文件。

在根目录下新建名为Farewell 的Assembly Definition 文件。

使用
引用Editor 命名空间,在对应的字段上添加标签
using Editor;
using UnityEngine;
namespace Player
{
public class ActorController : MonoBehaviour
{
[FieldName("移动速度")]
public float moveSpeed = 1.3f;
}
}
|