[Unity]自定义Inspector字段显示名称
2019/11
02
22:11
一、新建运行时TitleAttribute.cs脚本
using UnityEngine;
public class TitleAttribute : PropertyAttribute
{
public string newTitle { get ; private set; }
public TitleAttribute( string title )
{
newTitle = title ;
}
}
二、新建Editor目录中的脚本
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(TitleAttribute))]
public class TitleAttributeDrawer : PropertyDrawer
{
public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
{
EditorGUI.PropertyField(position, property, new GUIContent( (attribute as TitleAttribute).newTitle ));
}
}
三、使用
在需要用的地方添加[Title]标记:
[Title("角色ID")]
public string actorId;
四、效果
CopyRights: The Post by BY-NC-SA For Authorization,Original If Not Noted,Reprint Please Indicate From 老刘@开发笔记
Post Link: [Unity]自定义Inspector字段显示名称
Post Link: [Unity]自定义Inspector字段显示名称