153 lines
3.7 KiB
C#
153 lines
3.7 KiB
C#
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<GameObject> ItemList;
|
|
|
|
public Transform CreateParentToDay;
|
|
public Transform CreateParentLastDay;
|
|
|
|
public ListItem SelfList;//自己排名
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
instance = this;
|
|
returnBtn.onClick.AddListener(OnClickReBtn);
|
|
|
|
// 初始化 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);
|
|
}
|
|
}
|
|
|
|
// 第二个 Toggle 的变化事件
|
|
private void OnToggle2Changed(bool isOn)
|
|
{
|
|
if (isOn)
|
|
{
|
|
SetMarsk(1);
|
|
panel1.SetActive(false);
|
|
panel2.SetActive(true);
|
|
}
|
|
}
|
|
|
|
// 根据当前 Toggle 的状态初始化面板
|
|
private void UpdatePanels()
|
|
{
|
|
panel1.SetActive(toggle1.isOn);
|
|
panel2.SetActive(toggle2.isOn);
|
|
}
|
|
|
|
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<gameEscapeUserBetResponseVoList> gameData,Transform parent)
|
|
{
|
|
foreach (gameEscapeUserBetResponseVoList item in gameData)
|
|
{
|
|
|
|
GameObject newPanel = Instantiate(ListItemPre, parent);
|
|
|
|
|
|
ListItem panelComponent = newPanel.GetComponent<ListItem>();
|
|
|
|
// 设置实例化对象的内容
|
|
panelComponent.list=item.orderNo;
|
|
panelComponent.nameText.text=item.nickName;
|
|
panelComponent.nameText.text = item.bet.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否已存在
|
|
bool exists = false;
|
|
foreach (GameObject panel in ItemList)
|
|
{
|
|
if (panel.GetComponent<ListItem>().list == item.orderNo)
|
|
{
|
|
exists = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 如果不存在,则添加到列表
|
|
if (!exists)
|
|
{
|
|
ItemList.Add(newPanel);
|
|
|
|
}
|
|
else
|
|
{
|
|
// 如果已存在,可以根据需求决定是否销毁该实例
|
|
Destroy(newPanel);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void SetSelfList(userBetInfo info)
|
|
{
|
|
SelfList.list=info.orderNo;
|
|
SelfList.nameText.text=info.nickName;
|
|
SelfList.numText.text=info.bet.ToString();
|
|
SelfList.headPath = info.headImg;
|
|
|
|
SelfList.SetListImage();
|
|
SelfList.ListBgImage();
|
|
}
|
|
}
|