Change: add CreateListViewFromSettingsAttribute

This commit is contained in:
AnnulusGames 2024-02-21 09:58:39 +09:00
parent d874e72f18
commit 0d1063b13a
2 changed files with 29 additions and 24 deletions

View File

@ -18,31 +18,19 @@ namespace Alchemy.Editor.Elements
var settings = property.GetAttribute<ListViewSettingsAttribute>(true);
var listView = new ListView
var listView = GUIHelper.CreateListViewFromSettingsAttribute(settings);
listView.headerTitle = ObjectNames.NicifyVariableName(property.displayName);
listView.bindItem = (element, index) =>
{
reorderable = settings == null ? true : settings.Reorderable,
reorderMode = settings == null ? ListViewReorderMode.Animated : settings.ReorderMode,
showBorder = settings == null ? true : settings.ShowBorder,
showFoldoutHeader = settings == null ? true : settings.ShowFoldoutHeader,
showBoundCollectionSize = settings == null ? true : (settings.ShowFoldoutHeader && settings.ShowBoundCollectionSize),
selectionType = settings == null ? SelectionType.Multiple : settings.SelectionType,
headerTitle = ObjectNames.NicifyVariableName(property.displayName),
showAddRemoveFooter = settings == null ? true : settings.ShowAddRemoveFooter,
fixedItemHeight = 20f,
virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight,
showAlternatingRowBackgrounds = settings == null ? AlternatingRowBackground.None : settings.ShowAlternatingRowBackgrounds,
bindItem = (element, index) =>
{
var arrayElement = property.GetArrayElementAtIndex(index);
var e = new AlchemyPropertyField(arrayElement, property.GetPropertyType(true), depth + 1, true);
element.Add(e);
element.Bind(arrayElement.serializedObject);
},
unbindItem = (element, index) =>
{
element.Clear();
element.Unbind();
}
var arrayElement = property.GetArrayElementAtIndex(index);
var e = new AlchemyPropertyField(arrayElement, property.GetPropertyType(true), depth + 1, true);
element.Add(e);
element.Bind(arrayElement.serializedObject);
};
listView.unbindItem = (element, index) =>
{
element.Clear();
element.Unbind();
};
var label = listView.Q<Label>();

View File

@ -51,6 +51,23 @@ namespace Alchemy.Editor
};
}
public static ListView CreateListViewFromSettingsAttribute(ListViewSettingsAttribute settings)
{
return new ListView
{
reorderable = settings == null ? true : settings.Reorderable,
reorderMode = settings == null ? ListViewReorderMode.Animated : settings.ReorderMode,
showBorder = settings == null ? true : settings.ShowBorder,
showFoldoutHeader = settings == null ? true : settings.ShowFoldoutHeader,
showBoundCollectionSize = settings == null ? true : (settings.ShowFoldoutHeader && settings.ShowBoundCollectionSize),
selectionType = settings == null ? SelectionType.Multiple : settings.SelectionType,
showAddRemoveFooter = settings == null ? true : settings.ShowAddRemoveFooter,
fixedItemHeight = 20f,
virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight,
showAlternatingRowBackgrounds = settings == null ? AlternatingRowBackground.None : settings.ShowAlternatingRowBackgrounds,
};
}
public static PropertyField CreateObjectPropertyField(SerializedProperty property, Type type)
{
Assert.IsTrue(property.propertyType == SerializedPropertyType.ObjectReference);