Add: Support replacing the label text of each list element

This commit is contained in:
yuyu0127 2024-03-17 00:23:35 +09:00 committed by yuyu0217
parent bcaeef5ea9
commit 7409bf911c
3 changed files with 17 additions and 4 deletions

View File

@ -94,6 +94,9 @@ namespace Alchemy.Editor.Elements
break;
case PropertyField propertyField:
propertyField.label = value;
// To reflect changes, simply setting the value to the label property is not enough,
// so you need to directly modify the label of elements with a specific class.
propertyField.Query<Label>(className: "unity-property-field__label").ForEach(x => x.text = value);
break;
case SerializeReferenceField serializeReferenceField:
serializeReferenceField.foldout.text = value;

View File

@ -25,16 +25,25 @@ namespace Alchemy.Editor.Elements
{
var arrayElement = property.GetArrayElementAtIndex(index);
var e = new AlchemyPropertyField(arrayElement, property.GetPropertyType(true), true);
var elementLabelTextSelector = property.GetAttribute<ListViewSettingsAttribute>()?.ElementLabelTextSelector;
if (!string.IsNullOrEmpty(elementLabelTextSelector))
{
e.Label = (string)ReflectionHelper.Invoke(parentObj, elementLabelTextSelector, index);
}
element.Add(e);
element.Bind(arrayElement.serializedObject);
if (events != null)
{
e.TrackPropertyValue(arrayElement, x =>
{
if (events != null)
{
ReflectionHelper.Invoke(parentObj, events.OnItemChanged,
new object[] { index, x.GetValue<object>() });
});
}
if (!string.IsNullOrEmpty(elementLabelTextSelector))
{
e.Label = (string)ReflectionHelper.Invoke(parentObj, elementLabelTextSelector, index);
}
});
};
listView.unbindItem = (element, index) =>
{

View File

@ -216,6 +216,7 @@ namespace Alchemy.Inspector
public SelectionType SelectionType { get; set; } = SelectionType.Multiple;
public bool Reorderable { get; set; } = true;
public ListViewReorderMode ReorderMode { get; set; } = ListViewReorderMode.Animated;
public string ElementLabelTextSelector { get; set; } = null;
}
[AttributeUsage(AttributeTargets.Field)]