微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Unity Inspector 绘制备注信息 多语言辅助

属性

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[AttributeUsage(AttributeTargets.Field, Inherited = true)]
public class LanguageLabelAttribute : PropertyAttribute {
}

 

绘制

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(LanguageLabelAttribute))]
public class LanguageLabelPropertyDrawer : PropertyDrawer {
    private static readonly string errorLanguageKeyTips = "语言表 Key 不存在";

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
        var key = property.stringValue;

        //var content = !LanguageConfig.Has(key) ? errorLanguageKeyTips : Language.Get(key);
        var content = "哈哈哈";

        var propertyWidth = position.width / 4 * 3;
        var singleWidth = position.width / 4;

        EditorGUI.BeginProperty(position, label, property);
        var rect = new Rect(position.x, position.y, propertyWidth, position.height);
        EditorGUI.PropertyField(rect, property);
        EditorGUI.Endproperty();

        rect = new Rect(rect.xMax, rect.y, singleWidth, rect.height);
        using (new EditorGUI.disabledScope(true)) {
            EditorGUI.TextField(rect, content);
        }
    }
}

 

使用

    [LanguageLabelAttribute]
    public string str;

效果

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐