using System; using System.Linq; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.U2D.Animation { internal class SelectListView : ListView { public class CustomUxmlFactory : UxmlFactory {} public new void AddToSelection(int index) { base.AddToSelection(index); } public new void ClearSelection() { base.ClearSelection(); } } internal class SpriteBoneInfluenceListWidget : VisualElement { public class CustomUxmlFactory : UxmlFactory {} public class CustomUxmlTraits : UxmlTraits {} private List m_BoneInfluences; private SelectListView m_ListView; bool m_IgnoreSelectionChange = false; private Button m_AddButton; private Button m_RemoveButton; public Action onAddBone = () => {}; public Action onRemoveBone = () => {}; public Action> onReordered = _ => {}; public Action> onSelectionChanged = (s) => {}; public Func GetController = () => null; public SpriteBoneInfluenceListWidget() { var visualTree = ResourceLoader.Load("SkinningModule/SpriteBoneInfluenceListWidget.uxml"); var ve = visualTree.CloneTree().Q("Container"); ve.styleSheets.Add(ResourceLoader.Load("SkinningModule/SpriteBoneInfluenceListWidgetStyle.uss")); if (EditorGUIUtility.isProSkin) AddToClassList("Dark"); this.Add(ve); BindElements(); } private void BindElements() { m_ListView = this.Q(); m_ListView.selectionType = SelectionType.Multiple; m_ListView.itemsSource = m_BoneInfluences; m_ListView.makeItem = () => { var label = new Label() { name = "ListRow" }; return label; }; m_ListView.bindItem = (e, index) => { if (m_BoneInfluences[index] == null) return; (e as Label).text = m_BoneInfluences[index].name; if (index % 2 == 0) { e.RemoveFromClassList("ListRowOddColor"); e.AddToClassList("ListRowEvenColor"); } else { e.RemoveFromClassList("ListRowEvenColor"); e.AddToClassList("ListRowOddColor"); } }; m_ListView.onSelectionChange += OnListViewSelectionChanged; m_AddButton = this.Q