WXGame/box1/Assets/Script/UI/MainPanel.cs
2024-11-29 21:37:01 +08:00

140 lines
4.2 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 GameObject startPanel;//开始界面
[SerializeField] private GameObject levelPanel;//关卡界面
[SerializeField] private PackPanel packPanel;//背包界面
[SerializeField] private WinPanel winPanel;//胜利界面
[SerializeField] private LosePanel losePanel;//失败界面
[SerializeField] private TourPanel tourPanel;//旅行界面
[SerializeField] private HomePanel homePanel;//家园界面
[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;
winrestButton.onClick.AddListener(StartPanelEvent);
wincloseButton.onClick.AddListener(ClosePanelEvent);
loseRestButton.onClick.AddListener(StartPanelEvent);
loseCloseButton.onClick.AddListener(ClosePanelEvent);
}
/// <summary>
/// 关闭页面方法
/// </summary>
public void ClosePanelEvent()
{
GameManager.ins.start = false;
// startPanel.SetActive(true);
// winPanel.SetActive(false);
// packPanel.gameObject.SetActive(false);
// losePanel.SetActive(false);
// tourPanel.SetActive(false);
OpenLevelPanel();
}
public void OpenLevelPanel()
{
GameManager.ins.soundSystem.MainAudio();
startPanel.SetActive(false);
winPanel.gameObject.SetActive(false);
losePanel.gameObject.SetActive(false);
packPanel.gameObject.SetActive(false);
levelPanel.SetActive(true);
tourPanel.gameObject.SetActive(false);
homePanel.gameObject.SetActive(false);
levelPanel.GetComponent<LevelPanel>().StartPanel(DataManager.chapter);
}
/// <summary>
/// 开始游戏页面方法
/// </summary>
public void StartPanelEvent()
{
GameManager.ins.soundSystem.PackAudio();
startPanel.SetActive(false);
levelPanel.gameObject.SetActive(false);
winPanel.gameObject.SetActive(false);
losePanel.gameObject.SetActive(false);
packPanel.gameObject.SetActive(true);
packPanel.ResetTextData();
// _textMeshPro.text = "剩余箱子数:" + (GameManager.ins.index - 1);
ResetPropattributes();
}
public void StartTourPanel()
{
GameManager.ins.soundSystem.tourAudio();
GameManager.ins.start = false;
startPanel.SetActive(false);
winPanel.gameObject.SetActive(false);
packPanel.gameObject.SetActive(false);
losePanel.gameObject.SetActive(false);
tourPanel.gameObject.SetActive(true);
tourPanel.GetComponent<TourPanel>().StartVoid();
}
/// <summary>
/// 胜利页面
/// </summary>
public void Win()
{
winPanel.gameObject.SetActive(true);
winPanel.SaveData(GameManager.ins.level);
}
/// <summary>
/// 失败页面
/// </summary>
public void Lose()
{
losePanel.gameObject.SetActive(true);
losePanel.SaveData(GameManager.ins.level);
}
/// <summary>
/// 家园界面
/// </summary>
public void HomePanel()
{
DataManager.SaveAllStarNum();
homePanel.gameObject.SetActive(true);
startPanel.SetActive(false);
winPanel.gameObject.SetActive(false);
losePanel.gameObject.SetActive(false);
packPanel.gameObject.SetActive(false);
levelPanel.SetActive(false);
tourPanel.gameObject.SetActive(false);
homePanel.ResetImage();
}
// Start is called before the first frame update
void Start()
{
ClosePanelEvent();
}
public void ResetPropattributes()
{
packPanel.ResetPropattributes();
}
public void AddTourPanel(int addTime)
{
GameManager.ins.soundSystem.tourAudio();
tourPanel.AddTime(addTime);
}
// Update is called once per frame
void Update()
{
}
}