_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/ListPanel.cs

89 lines
2.1 KiB
C#
Raw Normal View History

2024-11-23 21:47:04 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ListPanel : BasePanel
{
public static ListPanel instance;
public Button returnBtn;
2024-11-23 23:44:16 +08:00
public Toggle toggle1; // <20><>һ<EFBFBD><D2BB> Toggle
public Toggle toggle2; // <20>ڶ<EFBFBD><DAB6><EFBFBD> Toggle
public GameObject panel1; // <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public GameObject panel2; // <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-24 00:01:23 +08:00
public Transform tog1;
public Transform tog2;
public Transform parent1;//<2F>ɰ常<C9B0><E5B8B8><EFBFBD><EFBFBD>
public Transform parent2;
public Transform Orparent1;//ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Transform Orparent2;
2024-11-23 21:47:04 +08:00
public override void Start()
{
base.Start();
instance = this;
returnBtn.onClick.AddListener(OnClickReBtn);
2024-11-23 23:44:16 +08:00
// <20><>ʼ<EFBFBD><CABC> Toggle <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>¼<EFBFBD>
toggle1.onValueChanged.AddListener(OnToggle1Changed);
toggle2.onValueChanged.AddListener(OnToggle2Changed);
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Toggle <20>ij<EFBFBD>ʼֵ
UpdatePanels();
}
// <20><>һ<EFBFBD><D2BB> Toggle <20>ı<C4B1>¼<EFBFBD>
private void OnToggle1Changed(bool isOn)
{
if (isOn)
{
2024-11-24 00:01:23 +08:00
SetMarsk(2);
2024-11-23 23:44:16 +08:00
panel1.SetActive(true);
panel2.SetActive(false);
}
2024-11-23 21:47:04 +08:00
}
2024-11-23 23:44:16 +08:00
// <20>ڶ<EFBFBD><DAB6><EFBFBD> Toggle <20>ı<C4B1>¼<EFBFBD>
private void OnToggle2Changed(bool isOn)
{
if (isOn)
{
2024-11-24 00:01:23 +08:00
SetMarsk(1);
2024-11-23 23:44:16 +08:00
panel1.SetActive(false);
panel2.SetActive(true);
}
}
// <20><><EFBFBD>ݵ<EFBFBD>ǰ Toggle <20><>״̬<D7B4><CCAC>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void UpdatePanels()
{
panel1.SetActive(toggle1.isOn);
panel2.SetActive(toggle2.isOn);
}
void OnDestroy()
{
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
toggle1.onValueChanged.RemoveListener(OnToggle1Changed);
toggle2.onValueChanged.RemoveListener(OnToggle2Changed);
}
2024-11-23 21:47:04 +08:00
public void OnClickReBtn()
{
HidePanel();
}
2024-11-24 00:01:23 +08:00
public void SetMarsk(int i)
{
if (i==1)
{
tog1.SetParent(parent1);
tog2.SetParent(Orparent2);
}
else
{
tog1.SetParent(Orparent1);
tog2.SetParent(parent2);
}
}
2024-11-23 21:47:04 +08:00
}