ClickListener.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.SceneManagement;
  6. public class ClickListener : MonoBehaviour
  7. {
  8. public static ClickListener Instance;
  9. // ==================================================
  10. private void Awake() => Instance = this;
  11. private void Update() => DetectOperation();
  12. // ==================================================
  13. #region 检测点击
  14. private void DetectOperation()
  15. {
  16. if (Input.GetMouseButtonDown(0))
  17. {
  18. if (EventSystem.current.IsPointerOverGameObject())
  19. {
  20. SwitchResetSequence(false);
  21. SwitchResetSequence(true);
  22. }
  23. }
  24. return;
  25. }
  26. #endregion
  27. // ==================================================
  28. #region 开始暂停流程
  29. public void SwitchResetSequence(bool value)
  30. {
  31. if (value)
  32. {
  33. StartCoroutine(nameof(ResetStateAction));
  34. }
  35. else
  36. {
  37. StopCoroutine(nameof(ResetStateAction));
  38. }
  39. return;
  40. }
  41. #endregion
  42. // ==================================================
  43. #region 自动重置流程
  44. private IEnumerator ResetStateAction()
  45. {
  46. yield return new WaitForSeconds(60f);
  47. SceneManager.LoadScene(0);
  48. yield break;
  49. }
  50. #endregion
  51. }