WXGame/box1/Assets/Script/UI/MainPanel.cs
2024-10-29 15:22:32 +08:00

93 lines
2.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class MainPanel : MonoBehaviour
{
public static MainPanel ins;
[SerializeField] private Button _startButton;
[SerializeField] private Button _closeButton;
[SerializeField] private GameObject startPanel;
[SerializeField] private GameObject packPanel;
[SerializeField] private Button packButton;
[SerializeField] private GameObject winPanel;
[SerializeField] private GameObject losePanel;
[SerializeField] private Button winrestButton;
[SerializeField] private Button wincloseButton;
[SerializeField] private Button loseRestButton;
[SerializeField] private Button loseCloseButton;
[SerializeField] private TextMeshProUGUI _textMeshPro;
private void Awake()
{
ins = this;
_startButton.onClick.AddListener(StartPanelEvent);
_closeButton.onClick.AddListener(ClosePanelEvent);
winrestButton.onClick.AddListener(StartPanelEvent);
wincloseButton.onClick.AddListener(ClosePanelEvent);
loseRestButton.onClick.AddListener(StartPanelEvent);
loseCloseButton.onClick.AddListener(ClosePanelEvent);
packButton.onClick.AddListener(() =>
{
GameManager.ins.PackEvent();
_textMeshPro.text = "剩余箱子数" + (GameManager.ins.index - 1);
});
}
/// <summary>
/// 关闭页面方法
/// </summary>
private void ClosePanelEvent()
{
GameManager.ins.start = false;
startPanel.SetActive(true);
winPanel.SetActive(false);
packPanel.SetActive(false);
losePanel.SetActive(false);
_closeButton.gameObject.SetActive(false);
}
/// <summary>
/// 开始游戏页面方法
/// </summary>
private void StartPanelEvent()
{
startPanel.SetActive(false);
_closeButton.gameObject.SetActive(true);
winPanel.SetActive(false);
losePanel.SetActive(false);
packPanel.SetActive(true);
GameManager.ins.ResetPack();
_textMeshPro.text = "剩余箱子数:" + (GameManager.ins.index - 1);
}
/// <summary>
/// 胜利页面
/// </summary>
public void Win()
{
winPanel.SetActive(true);
_closeButton.gameObject.SetActive(false);
}
/// <summary>
/// 失败页面
/// </summary>
public void Lose()
{
_closeButton.gameObject.SetActive(false);
losePanel.SetActive(true);
}
// Start is called before the first frame update
void Start()
{
ClosePanelEvent();
}
// Update is called once per frame
void Update()
{
}
}