using Alchemy.Inspector;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UIElements;
namespace Alchemy.Editor.Elements
{
///
/// Visual Element that draws SerializedProperty of Array or List
///
public sealed class PropertyListView : BindableElement
{
public PropertyListView(SerializedProperty property)
{
Assert.IsTrue(property.isArray);
var parentObj = property.GetDeclaredObject();
var events = property.GetAttribute(true);
listView = GUIHelper.CreateListViewFromFieldInfo(parentObj, property.GetFieldInfo());
listView.headerTitle = ObjectNames.NicifyVariableName(property.displayName);
listView.bindItem = (element, index) =>
{
var arrayElement = property.GetArrayElementAtIndex(index);
var e = new AlchemyPropertyField(arrayElement, property.GetPropertyType(true), true);
element.Add(e);
element.Bind(arrayElement.serializedObject);
if (events != null)
{
e.TrackPropertyValue(arrayElement, x =>
{
ReflectionHelper.Invoke(parentObj, events.OnItemChanged,
new object[] { index, x.GetValue