MenuUI.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using UnityEngine;
  3. public class MenuUI : MonoBehaviour
  4. {
  5. // 主菜单UI容器
  6. [SerializeField] private GameObject menuUIWrapper;
  7. // 开始按钮音效
  8. [SerializeField] private AudioSource startAudioSource;
  9. // 教程引导UI容器
  10. [SerializeField] private GameObject TutorialWrapper;
  11. // 是否已按下开始按钮
  12. private bool _isPressed;
  13. /// <summary>
  14. /// 初始化,若已完成教程则销毁教程UI
  15. /// </summary>
  16. private void Awake()
  17. {
  18. if (PlayerPrefs.HasKey("Tutorial"))
  19. Destroy(TutorialWrapper);
  20. _isPressed = false; // 场景重载时重置
  21. if (menuUIWrapper != null)
  22. menuUIWrapper.SetActive(false); // 默认先隐藏主菜单,防止误触
  23. }
  24. private void Start()
  25. {
  26. if (menuUIWrapper != null)
  27. StartCoroutine(ShowMenuWithDelay());
  28. }
  29. private System.Collections.IEnumerator ShowMenuWithDelay()
  30. {
  31. yield return new WaitForSeconds(1.5f);
  32. if (menuUIWrapper != null)
  33. menuUIWrapper.SetActive(true);
  34. }
  35. /// <summary>
  36. /// 激活或隐藏主菜单UI,并处理教程引导
  37. /// </summary>
  38. /// <param name="status">是否显示菜单</param>
  39. public void ActivateMenu(bool status)
  40. {
  41. if (status)
  42. {
  43. startAudioSource.Play();
  44. if (ComponentsManager.Tutorial)
  45. {
  46. if (ComponentsManager.Tutorial.GetStep == 0)
  47. ComponentsManager.Tutorial.NextStep(1, true);
  48. }
  49. }
  50. menuUIWrapper.SetActive(status);
  51. }
  52. /// <summary>
  53. /// 监听E键,调试用:添加金币
  54. /// </summary>
  55. private void Update()
  56. {
  57. if (Input.GetKeyDown(KeyCode.E))
  58. {
  59. ComponentsManager.PlayerWallet.AddMoney(0);
  60. }
  61. }
  62. /// <summary>
  63. /// 开始战斗按钮点击,启动战斗并隐藏菜单,处理教程步骤
  64. /// </summary>
  65. public void StartBattleButton()
  66. {
  67. ComponentsManager.BattleManager.StartBattle();
  68. ActivateMenu(false);
  69. if (!_isPressed)
  70. {
  71. _isPressed = true;
  72. }
  73. if (ComponentsManager.Tutorial)
  74. {
  75. if (ComponentsManager.Tutorial.GetStep == 0)
  76. ComponentsManager.Tutorial.NextStep(0, false);
  77. if (ComponentsManager.Tutorial.GetStep == 2)
  78. ComponentsManager.Tutorial.NextStep(2, false);
  79. if (ComponentsManager.Tutorial.GetStep == 4)
  80. ComponentsManager.Tutorial.NextStep(5, false);
  81. }
  82. }
  83. }