using Assets.Scenes.Ride.Scripts; using Assets.Scripts; using Assets.Scripts.Apis.Models; using PolyAndCode.UI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; class GameRoomList : MonoBehaviour, IRecyclableScrollRectDataSource { [SerializeField] RecyclableScrollRect _recyclableScrollRect; [SerializeField] RectTransform _rectTransform; [SerializeField] InputField _searchInputField; [SerializeField] GameObject _searchBtn; [SerializeField] private int _dataLength; private bool _isInit; //Dummy data List private List _list = new List(); //Recyclable scroll rect's data source must be assigned in Awake. private void Awake() { _recyclableScrollRect.DataSource = this; _ = GetDataAsync(); _searchInputField.onValueChanged.AddListener((e) => { if (!string.IsNullOrEmpty(e)) { _ = GetDataAsync(Convert.ToInt32(e)); } else { _ = GetDataAsync(); } }); UIManager.AddEvent(_searchBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Refreash); } private void Refreash(BaseEventData data) { _ = GetDataAsync(); } private async Task GetDataAsync(int? id =null) { if (_list != null) _list.Clear(); var result = await ConfigHelper.GameRoomApi.GetList(0, 1000, id); if (result.result) { _list = result.data; _recyclableScrollRect.ReloadData(); } } float timer = 1f; private void Update() { timer -= Time.deltaTime; while (timer < 0) { timer += 1f; } } #region DATA-SOURCE /// /// Data source method. return the list length. /// public int GetItemCount() { return _list.Count; } /// /// Data source method. Called for a cell every time it is recycled. /// Implement this method to do the necessary cell configuration. /// public void SetCell(ICell cell, int index) { //Casting to the implemented Cell var item = cell as GameRoomCell; item.ConfigureCell(_list[index], index); } #endregion }