1.12.0: Added FieldLabelFromArrayIndex
This commit is contained in:
parent
df1d2f6df1
commit
23b24d42d3
6 changed files with 71 additions and 1 deletions
36
Editor/Predrawers/FieldLabelFromArrayIndexAttributeDrawer.cs
Normal file
36
Editor/Predrawers/FieldLabelFromArrayIndexAttributeDrawer.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3d86ca907fc4263af776ff820941320
|
||||
timeCreated: 1781374403
|
||||
Loading…
Add table
Add a link
Reference in a new issue