using Assets.Scenes.Ride.Scripts; using PolyAndCode.UI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace Assets.Scripts.Scenes.VideoRide { public struct ContactInfo { public string Name; public string Gender; public string id; } class NearVideoPlayerList : MonoBehaviour, IRecyclableScrollRectDataSource { [SerializeField] RecyclableScrollRect _recyclableScrollRect; [SerializeField] private int _dataLength; //Dummy data List private List _contactList = new List(); //Recyclable scroll rect's data source must be assigned in Awake. private void Awake() { InitData(); _recyclableScrollRect.DataSource = this; } private void InitData() { if (_contactList != null) _contactList.Clear(); var list = MapUDPService.GetOnlineUsers(App.RouteIdParam); foreach (var item in list) { ContactInfo obj = new ContactInfo(); obj.Name = item.Name; obj.Gender = DateTime.Now.Millisecond.ToString(); obj.id = item.Id.ToString(); _contactList.Add(obj); } } float timer = 1f; private void Update() { timer -= Time.deltaTime; while (timer < 0) { InitData(); timer += 1f; } } #region DATA-SOURCE /// /// Data source method. return the list length. /// public int GetItemCount() { return _contactList.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 ListItem; item.ConfigureCell(_contactList[index], index); } #endregion } }