1.10.0: Added FieldLabelFromEnum for elements in an array

This commit is contained in:
Anders Ejlersen 2024-11-21 19:30:29 +01:00
parent ea527c9b33
commit a804633a14
6 changed files with 74 additions and 1 deletions

View file

@ -0,0 +1,42 @@
using System;
using UnityEditor;
using UnityEngine;
namespace Module.Inspector.Editor
{
[CustomPropertyDrawer(typeof(FieldLabelFromEnumAttribute))]
internal sealed class FieldLabelFromEnumAttributeDrawer : PredrawerModifierPropertyDrawer
{
public override void Modify(PredrawerModifierPropertyAttribute attribute, SerializedProperty property, GUIContent label)
{
var att = (FieldLabelFromEnumAttribute)attribute;
if (!att.type.IsEnum)
return;
SerializedProperty sp = property.GetParent();
if (sp == null)
return;
var index = sp.IndexOfProperty(property);
if (index == -1)
return;
try
{
string str = Enum.GetName(att.type, index);
if (att.nicify)
str = ObjectNames.NicifyVariableName(str);
label.text = str;
}
catch (Exception)
{
// Ignore
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: af2e8cbad9e548688949c9dc4d1a127e
timeCreated: 1732212390