123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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;
- /// <summary>
- /// 初始化,若已完成教程则销毁教程UI
- /// </summary>
- 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);
- }
- /// <summary>
- /// 激活或隐藏主菜单UI,并处理教程引导
- /// </summary>
- /// <param name="status">是否显示菜单</param>
- 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);
- }
- /// <summary>
- /// 监听E键,调试用:添加金币
- /// </summary>
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.E))
- {
- ComponentsManager.PlayerWallet.AddMoney(0);
- }
- }
- /// <summary>
- /// 开始战斗按钮点击,启动战斗并隐藏菜单,处理教程步骤
- /// </summary>
- 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);
- }
- }
- }
|