Unity3D笔记(十五)在Unity编辑器中显示中文字段

2019-06-05  本文已影响0人  鲫鱼汤

方法一[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下是不能打包的,所以第三种方法只适合在开发中方便我们配置,在打包的时候需要删除或修改。

上一篇 下一篇

猜你喜欢

热点阅读