확장을 편집하여 검사기 매개 변수의 이름을 단순화합니다.

4602 단어 Unity 확장Unity

등록 정보


CustomLabelAttribute.cs
using UnityEngine;

public class CustomLabelAttribute : PropertyAttribute
{
    public readonly string Value;

    public CustomLabelAttribute(string value)
    {
        Value = value;
    }
}

편집기 측 코드


CustomLabelDrawer.cs

using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(CustomLabelAttribute))]
public class CustomLabelDrawer : PropertyDrawer
{
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var newLabel = attribute as CustomLabelAttribute;
            EditorGUI.PropertyField(position, property, new GUIContent(newLabel.Value), true);
        }

        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return EditorGUI.GetPropertyHeight(property, true);
        }
}
추기 2019/7/19
Rect, 정렬 등 여러 줄 지원

사용자 코드 샘플


UseCustomLabelAttribute.cs
using UnityEngine;

public class UseCustomLabelAttribute : MonoBehaviour
{
    [CustomLabel("カウント")]
    public int Count;
}

적용 전



응용 후



항상 이름만 바꾸고 싶은 게 있어요.
유니티의 표준 기능이라 찾아도 찾을 수 없어서 했어요.
경쟁 같은 거 전혀 생각 안 했어요.

좋은 웹페이지 즐겨찾기