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

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

作者: 鲫鱼汤 | 来源:发表于2019-06-05 17:11 被阅读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下是不能打包的,所以第三种方法只适合在开发中方便我们配置,在打包的时候需要删除或修改。

相关文章

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/plssxctx.html