using System; using UnityEngine; public class MenuUI : MonoBehaviour { // 主菜单UI容器 [SerializeField] private GameObject menuUIWrapper; // 开始按钮音效 [SerializeField] private AudioSource startAudioSource; // 教程引导UI容器 [SerializeField] private GameObject TutorialWrapper; // 是否已按下开始按钮 private bool _isPressed; /// /// 初始化,若已完成教程则销毁教程UI /// private void Awake() { if (PlayerPrefs.HasKey("Tutorial")) Destroy(TutorialWrapper); _isPressed = false; // 场景重载时重置 if (menuUIWrapper != null) menuUIWrapper.SetActive(false); // 默认先隐藏主菜单,防止误触 } private void Start() { if (menuUIWrapper != null) StartCoroutine(ShowMenuWithDelay()); } private System.Collections.IEnumerator ShowMenuWithDelay() { yield return new WaitForSeconds(1.5f); if (menuUIWrapper != null) menuUIWrapper.SetActive(true); } /// /// 激活或隐藏主菜单UI,并处理教程引导 /// /// 是否显示菜单 public void ActivateMenu(bool status) { if (status) { startAudioSource.Play(); if (ComponentsManager.Tutorial) { if (ComponentsManager.Tutorial.GetStep == 0) ComponentsManager.Tutorial.NextStep(1, true); } } menuUIWrapper.SetActive(status); } /// /// 监听E键,调试用:添加金币 /// private void Update() { if (Input.GetKeyDown(KeyCode.E)) { ComponentsManager.PlayerWallet.AddMoney(0); } } /// /// 开始战斗按钮点击,启动战斗并隐藏菜单,处理教程步骤 /// public void StartBattleButton() { ComponentsManager.BattleManager.StartBattle(); ActivateMenu(false); if (!_isPressed) { _isPressed = true; } if (ComponentsManager.Tutorial) { if (ComponentsManager.Tutorial.GetStep == 0) ComponentsManager.Tutorial.NextStep(0, false); if (ComponentsManager.Tutorial.GetStep == 2) ComponentsManager.Tutorial.NextStep(2, false); if (ComponentsManager.Tutorial.GetStep == 4) ComponentsManager.Tutorial.NextStep(5, false); } } }