Files
MinFt/Client/Assets/Scripts/UI/InfoPopupPanel/PageInfoPopupPanel.cs
2026-04-27 12:07:32 +08:00

126 lines
3.4 KiB
C#

using GameCore;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PageInfoPopupPanel : MonoBehaviour
{
const string PageInfoPopupPanelKey = "PageInfoPopupPanel";
Button btnBack;
Button btnClose;
Button btn_left;
Button btn_right;
GameObject text_continue;
GameObject ImageItem;
List<GameObject> ImageItemList = new List<GameObject>();
List<GameObject> selectGos = new List<GameObject>();
[SerializeField]
List<GameObject> page = new List<GameObject>();
int index = 0;
int allCount = 0;
private void Awake()
{
btnBack = transform.Find("mask").GetComponent<Button>();
btnClose = transform.Find("btn_close").GetComponent<Button>();
btn_left = transform.Find("btn_close/btn_left").GetComponent<Button>();
btn_right = transform.Find("btn_close/btn_right").GetComponent<Button>();
text_continue = transform.Find("text_continue").gameObject;
ImageItem = transform.Find("root/Sliding/ImageItem").gameObject;
ImageItem.SetActive(false);
allCount = page.Count;
InitPanel();
}
private void Start()
{
btnClose.onClick.AddListener(OnClickClose);
btn_left.onClick.AddListener(OnLeftClick);
btn_right.onClick.AddListener(OnRightClick);
string value = PlayerPrefs.GetString(PageInfoPopupPanelKey, "");
string gameObjectName = gameObject.name.Split("InfoPopupPanel")[0];
bool iscontain = value.Contains(gameObjectName);
if (!iscontain)
{
PlayerPrefs.SetString(PageInfoPopupPanelKey, value + gameObjectName);
}
btnBack.enabled = !iscontain;
btnClose.gameObject.SetActive(iscontain);
text_continue.SetActive(!iscontain);
btnBack.onClick.AddListener(BackClick);
SetData();
}
void InitPanel()
{
int curCount = ImageItemList.Count;
if (curCount < allCount)
{
for (int i = curCount; i < allCount; i++)
{
GameObject go = Instantiate(ImageItem, ImageItem.transform.parent);
go.SetActive(true);
selectGos.Add(go.transform.Find("Select").gameObject);
ImageItemList.Add(go);
}
}
else if (curCount > allCount)
{
for (int i = allCount; i < curCount; i++)
{
ImageItemList[i].SetActive(false);
}
}
}
void SetSelect()
{
for (int i = 0; i < selectGos.Count; i++)
{
selectGos[i].SetActive(i == index);
}
}
void OnLeftClick()
{
if (index > 0)
{
index--;
SetData();
}
}
void OnRightClick()
{
if (index < allCount - 1)
{
index++;
SetData();
}
}
void BackClick()
{
if (index < allCount - 1)
{
index++;
SetData();
if (index == allCount - 1)
{
btnClose.gameObject.SetActive(true);
text_continue.SetActive(false);
btnBack.enabled = false;
}
}
}
void SetData()
{
for (int i = 0; i < page.Count; i++)
{
page[i].gameObject.SetActive(i == index);
}
SetSelect();
}
private void OnClickClose()
{
UIManager.Instance.DestroyUI(gameObject.name);
}
}