Unity3D筆記(十五)在Unity編輯器中顯示中文字段

方法一[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ā)中方便我們配置,在打包的時候需要刪除或修改。

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容