【Unity】リストの各要素のラベルをそのクラスのenumの文字列にするエディタ拡張

こんな感じで各クラスに含まれるenumの値を参照してヘッダーとして表示してくれる。
(通常はElement 0などで表示される部分)

Attribute

using UnityEngine;

public class EnumListAttribute : PropertyAttribute
{
    public string EnumPropertyName = null;

    public EnumListAttribute(string enumPropertyName)
    {
        this.EnumPropertyName = enumPropertyName;
    }
}

PropertyDrawer

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

[CustomPropertyDrawer(typeof(EnumListAttribute))]
public class EnumListDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var index = int.Parse(property.propertyPath.Split('[', ']').Where(c => !string.IsNullOrEmpty(c)).Last());
        var key = property.FindPropertyRelative(((EnumListAttribute)attribute).EnumPropertyName);
        if (key != null && key.propertyType == SerializedPropertyType.Enum)
        {
            var name = key.enumNames[key.enumValueIndex];
            label.text = name;
            EditorGUI.PropertyField(position, property, label, includeChildren: true);
        }
        else
        {
            EditorGUI.PropertyField(position, property, label);
        }
    }

    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        return EditorGUI.GetPropertyHeight(property, label, includeChildren: true);
    }
}

使い方

        [Serializable]
        public class TableData
        {
            public MyEnum Key;
            public string Value;
        }

        [SerializeField, EnumList(nameof(TableData.Key))]
        public TableData[] TableDataList = new TableData[0];