using Assets.MyGame.Scripts.Net; using Assets.MyGame.Scripts.Net.WebResponses; using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; public class UIHome_BY_MySelectRoomPanel : SubUIBase { public GameObject panel_PanelParent; public Button panel_RoomItemPrefab; public Button btn_NextPage; public Button btn_UpPage; public TextMeshProUGUI text_PageNum; public ScrollRect scroll; public List itemPage = new List(); public GameObject itemPagePrefab; public Transform itemPageParent; //public Dictionary> itemListDic=new Dictionary>(); public Dictionary itemListDic = new Dictionary(); int pageNum = 1; float horizontalNormalizedPosition; public override void Awake() { btn_NextPage.onClick.AddListener(() => { if (pageNum > 1) { pageNum--; } text_PageNum.text = pageNum + "/" + itemPage.Count; horizontalNormalizedPosition = (float)(pageNum - 1) / (float)(itemPage.Count - 1); }); btn_UpPage.onClick.AddListener(() => { if (pageNum < itemPage.Count) { pageNum++; } text_PageNum.text = pageNum + "/" + itemPage.Count; horizontalNormalizedPosition = (float)(pageNum - 1) / (float)(itemPage.Count - 1); }); btn_Close.onClick.AddListener(() => { Hide(); }); panel_RoomItemPrefab.onClick.AddListener(() => { GameManager.Instance.StartGame(); }); } private void Update() { scroll.horizontalNormalizedPosition = Mathf.Lerp(scroll.horizontalNormalizedPosition, horizontalNormalizedPosition, 0.5f); } public override void Hide() { base.Hide(); panel_PanelParent.SetActive(true); } public override void Show(object args = null) { base.Show(args); text_PageNum.text = pageNum + "/" + itemPage.Count; panel_PanelParent.SetActive(false); if (args != null) { int i = 0; var v = JsonConvert.DeserializeObject>>(args.ToString()); //var v = args as List; itemPage.Add(Instantiate(itemPagePrefab, itemPageParent).transform); int pageMax = Mathf.FloorToInt(v.arguments[0].Count / 15f); for (int j = 0; j < pageMax; j++) { itemPage.Add(Instantiate(itemPagePrefab, itemPageParent).transform); } foreach (var item in v.arguments[0]) { //itemListDic.Add Instantiate(panel_RoomItemPrefab, itemPage[(int)(i/15)-1]); var tran = Instantiate(panel_RoomItemPrefab.gameObject, itemPage[(int)(i / 15)]).transform; tran.name = item.roomId; itemListDic.Add(item.roomId, tran); var slider = tran.transform.GetChild(1).GetComponent(); int allPlayerCount = item.currentOnlinePlayerCount + item.robotCount; slider.value = (float)allPlayerCount / (float)item.maxPlayerCount; if (allPlayerCount == item.maxPlayerCount) { slider.fillRect.GetChild(0).gameObject.SetActive(true); } tran.transform.GetChild(2).GetComponent().text = allPlayerCount + "/" + item.maxPlayerCount; tran.transform.GetChild(3).GetComponent().text = item.roomNumber.ToString(); i++; } text_PageNum.text = 1 + "/" + itemPage.Count; scroll.horizontalNormalizedPosition = 0; pageNum = 1; } } }