1.10.0: Added FieldLabelFromEnum for elements in an array
This commit is contained in:
parent
ea527c9b33
commit
a804633a14
6 changed files with 74 additions and 1 deletions
42
Editor/Predrawers/FieldLabelFromEnumAttributeDrawer.cs
Normal file
42
Editor/Predrawers/FieldLabelFromEnumAttributeDrawer.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af2e8cbad9e548688949c9dc4d1a127e
|
||||
timeCreated: 1732212390
|
||||
Loading…
Add table
Add a link
Reference in a new issue