using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ListPanel : BasePanel { public static ListPanel instance; public Button returnBtn; public Toggle toggle1; // 第一个 Toggle public Toggle toggle2; // 第二个 Toggle public GameObject panel1; // 第一个面板 public GameObject panel2; // 第二个面板 public Transform tog1; public Transform tog2; public Transform parent1;//蒙板父物体 public Transform parent2; public Transform Orparent1;//原始父物体 public Transform Orparent2; public GameObject ListItemPre;//排行预制体 public List ItemList; public List ItemListLastDay; public Transform CreateParentToDay; public Transform CreateParentLastDay; public ListItem SelfListToDay;//自己排名 public ListItem SelfListLastDay;//自己排名 public AllHouseContro allHouseContro; public override void Start() { base.Start(); instance = this; returnBtn.onClick.AddListener(OnClickReBtn); allHouseContro.GetInfo518(); allHouseContro.GetInfo518(1); // 初始化 Toggle 的监听事件 toggle1.onValueChanged.AddListener(OnToggle1Changed); toggle2.onValueChanged.AddListener(OnToggle2Changed); // 初始化面板状态,根据 Toggle 的初始值 UpdatePanels(); } // 第一个 Toggle 的变化事件 private void OnToggle1Changed(bool isOn) { if (isOn) { SetMarsk(2); panel1.SetActive(true); panel2.SetActive(false); SelfListToDay.gameObject.SetActive(true); SelfListLastDay.gameObject.SetActive(false); } } // 第二个 Toggle 的变化事件 private void OnToggle2Changed(bool isOn) { if (isOn) { SetMarsk(1); panel1.SetActive(false); panel2.SetActive(true); SelfListLastDay.gameObject.SetActive(true); SelfListToDay.gameObject.SetActive(false); //allHouseContro.GetInfo518(1); } } // 根据当前 Toggle 的状态初始化面板 public void UpdatePanels() { panel1.SetActive(toggle1.isOn); panel2.SetActive(toggle2.isOn); } public void ShowPanels()//显示所有面板 { panel1.SetActive(true); panel2.SetActive(true); } void OnDestroy() { // 取消监听事件,避免内存泄漏 toggle1.onValueChanged.RemoveListener(OnToggle1Changed); toggle2.onValueChanged.RemoveListener(OnToggle2Changed); } public void OnClickReBtn() { HidePanel(); } public void SetMarsk(int i) { if (i==1) { tog1.SetParent(parent1); tog2.SetParent(Orparent2); } else { tog1.SetParent(Orparent1); tog2.SetParent(parent2); } } public void CreateListItem(List gameData,Transform parent,int flag=0) { foreach (gameEscapeUserBetResponseVoList item in gameData) { GameObject newPanel = Instantiate(ListItemPre, parent); ListItem panelComponent = newPanel.GetComponent(); // 设置实例化对象的内容 panelComponent.list=item.orderNo; panelComponent.listText.text= item.orderNo.ToString(); panelComponent.nameText.text=item.nickName; panelComponent.numText.text = item.bet.ToString(); if (flag==0) { // 判断是否已存在 bool exists = false; foreach (GameObject panel in ItemList) { if (panel.GetComponent().list == item.orderNo) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { ItemList.Add(newPanel); } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } else { // 判断是否已存在 bool exists = false; foreach (GameObject panel in ItemListLastDay) { if (panel.GetComponent().list == item.orderNo) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { ItemListLastDay.Add(newPanel); } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } } } public void SetSelfList(userBetInfo info,int flag=0) { if (flag==0) { SelfListToDay.listText.text = info.orderNo; SelfListToDay.nameText.text = info.nickName; SelfListToDay.numText.text = info.bet.ToString(); SelfListToDay.headPath = info.headImg; SelfListToDay.SetListImage(); SelfListToDay.ListBgImage(); } else { SelfListLastDay.listText.text = info.orderNo; SelfListLastDay.nameText.text = info.nickName; SelfListLastDay.numText.text = info.bet.ToString(); SelfListLastDay.headPath = info.headImg; SelfListLastDay.SetListImage(); SelfListLastDay.ListBgImage(); } } }