Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public string Label
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;
Expand Down
17 changes: 13 additions & 4 deletions Alchemy/Assets/Alchemy/Editor/Elements/PropertyListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ public PropertyListView(SerializedProperty property)
{
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 =>
{
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) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public sealed class ListViewSettingsAttribute : Attribute
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)]
Expand Down