99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
using Assets.Scenes.Ride.Scripts;
|
|
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using Assets.Scripts.UI.Control;
|
|
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
|
|
{
|
|
[SerializeField]
|
|
RectTransform _rectTransform;
|
|
|
|
[SerializeField]
|
|
InputField _searchInputField;
|
|
|
|
[SerializeField]
|
|
GameObject _searchBtn;
|
|
|
|
[SerializeField]
|
|
private int _dataLength;
|
|
private bool _isInit;
|
|
|
|
private GameObject RoomCell { get; set; }
|
|
|
|
//Dummy data List
|
|
private List<GameRoomModel> _list = new List<GameRoomModel>();
|
|
|
|
private string seachName = "";
|
|
PFUIPageHelper pageHelper;
|
|
|
|
//Recyclable scroll rect's data source must be assigned in Awake.
|
|
private void Awake()
|
|
{
|
|
RoomCell = Resources.Load<GameObject>("UI/Prefab/GameRoom/Room");
|
|
//分页
|
|
pageHelper = FindObjectOfType<PFUIPageHelper>();
|
|
pageHelper.PageIndex = 0;
|
|
pageHelper.PageSize = 6;
|
|
pageHelper.Register((e) =>
|
|
{
|
|
_ = GetDataAsync();
|
|
});
|
|
|
|
_ = GetDataAsync();
|
|
_searchInputField.onValueChanged.AddListener((e) => { seachName = e; });
|
|
_searchInputField.onEndEdit.AddListener((e) => {
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
_ = GetDataAsync();
|
|
}
|
|
else
|
|
{
|
|
_ = GetDataAsync();
|
|
}
|
|
});
|
|
UIManager.AddEvent(_searchBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Refreash);
|
|
}
|
|
private void Refreash(BaseEventData data)
|
|
{
|
|
_ = GetDataAsync();
|
|
}
|
|
private async Task GetDataAsync()
|
|
{
|
|
if (_list != null) _list.Clear();
|
|
var result = await ConfigHelper.GameRoomApi.GetList(pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
|
if (result.result)
|
|
{
|
|
Utils.DestroyChildren(_rectTransform);
|
|
_list = result.data.List;
|
|
int index = 0;
|
|
foreach (var item in _list)
|
|
{
|
|
index++;
|
|
var g = Instantiate(RoomCell, _rectTransform);
|
|
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
|
}
|
|
pageHelper.Total = result.data.Total;
|
|
pageHelper.Build();
|
|
}
|
|
}
|
|
float timer = 1f;
|
|
private void Update()
|
|
{
|
|
timer -= Time.deltaTime;
|
|
while (timer < 0)
|
|
{
|
|
timer += 1f;
|
|
}
|
|
}
|
|
}
|
|
|