using System; using System.Collections.Generic; using System.Linq; using UniRx; using static TMPro.TMP_Dropdown; namespace SharpUI.Source.Common.UI.Elements.DropDowns.Adapters { public abstract class DropDownAdapter : IDropDownAdapter where TData : class { private readonly Subject _dataChangeObserver = new Subject(); protected List data = new List(); public void SetData(IEnumerable newData) { data = new List(newData); NotifyDataSetChanged(); } public int DataCount() => data.Count; private void NotifyDataSetChanged() => _dataChangeObserver.OnNext(Unit.Default); public IObservable ObserveDataChange() => _dataChangeObserver; public List GetOptionsData() => data .Select((item, index) => new OptionData(GetItemTextAt(index))) .ToList(); public abstract string GetItemTextAt(int index); } }