1.12.0: Added FieldLabelFromArrayIndex

This commit is contained in:
Anders Ejlersen 2026-06-13 21:34:44 +02:00
parent df1d2f6df1
commit 23b24d42d3
6 changed files with 71 additions and 1 deletions

View file

@ -0,0 +1,36 @@
using System.Text;
using UnityEditor;
using UnityEngine;
namespace Module.Inspector.Editor
{
[CustomPropertyDrawer(typeof(FieldLabelFromArrayIndexAttribute))]
internal sealed class FieldLabelFroArrayIndexAttributeDrawer : PredrawerModifierPropertyDrawer
{
public override void Modify(PredrawerModifierPropertyAttribute attribute, SerializedProperty property, GUIContent label)
{
var att = (FieldLabelFromArrayIndexAttribute)attribute;
var spParent = property.GetParent();
if (spParent == null || !spParent.isArray)
return;
var index = spParent.IndexOfProperty(property);
if (index == -1)
return;
var builder = new StringBuilder();
if (!string.IsNullOrEmpty(att.prefix))
builder.Append(att.prefix);
builder.Append(index);
if (!string.IsNullOrEmpty(att.postfix))
builder.Append(att.postfix);
label.text = builder.ToString();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c3d86ca907fc4263af776ff820941320
timeCreated: 1781374403