UIPauseController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections;
  3. using Colorful;
  4. using Core;
  5. using DG.Tweening;
  6. using DG.Tweening.Core;
  7. using DG.Tweening.Plugins.Options;
  8. using UnityEngine;
  9. public class UIPauseController : MonoBehaviour
  10. {
  11. private bool HasEnteredLevelSelectSystem
  12. {
  13. get
  14. {
  15. return SaveStorage.Get("HasEnteredLevelSelectSystem", false);
  16. }
  17. set
  18. {
  19. SaveStorage.Set("HasEnteredLevelSelectSystem", value);
  20. }
  21. }
  22. private void Start()
  23. {
  24. EventDelegate.Add(this._resume.onClick, new EventDelegate.Callback(this.OnResumeClick));
  25. EventDelegate.Add(this._exit.onClick, new EventDelegate.Callback(this.OnExitClick));
  26. EventDelegate.Add(this._levelSelect.onClick, new EventDelegate.Callback(this.OnLevelSelect));
  27. }
  28. private void Update()
  29. {
  30. if (this._panel.gameObject.activeInHierarchy && Core.Input.UI.Cancel.OnClick)
  31. {
  32. this.OnResumeClick();
  33. }
  34. }
  35. public bool Enabled
  36. {
  37. get
  38. {
  39. return Core.Input.UI.Pause.IsOpen;
  40. }
  41. set
  42. {
  43. Core.Input.UI.Pause.IsOpen = value;
  44. SingletonMono<MobileInputPlayer>.Instance.OptionsVisible = value;
  45. }
  46. }
  47. private void Open()
  48. {
  49. this._levelSelect.transform.parent.gameObject.SetActive(this.HasEnteredLevelSelectSystem);
  50. R.Audio.PauseBGM();
  51. R.Mode.EnterMode(Mode.AllMode.UI);
  52. R.Ui.HideUI(true);
  53. UIKeyInput.SaveAndSetHoveredObject(this._resume.gameObject);
  54. this._panel.gameObject.SetActive(true);
  55. AnalogTV analogTV = R.Ui.CameraGO.AddComponent<AnalogTV>();
  56. analogTV.Shader = Shader.Find("Hidden/Colorful/Analog TV");
  57. analogTV.NoiseIntensity = 1f;
  58. analogTV.ScanlinesIntensity = 0f;
  59. analogTV.ScanlinesCount = 696;
  60. analogTV.Distortion = 0.18f;
  61. analogTV.CubicDistortion = 0f;
  62. analogTV.Scale = 1.02f;
  63. }
  64. public YieldInstruction PauseThenOpenWithAnim()
  65. {
  66. this.Open();
  67. this.Enabled = false;
  68. R.PauseGame();
  69. AnalogTV analogTV = R.Ui.CameraGO.GetComponent<AnalogTV>();
  70. analogTV.Scale = 0f;
  71. return DOTween.To(() => analogTV.Scale, delegate(float scale)
  72. {
  73. analogTV.Scale = scale;
  74. }, 1.02f, 0.5f).OnComplete(delegate
  75. {
  76. this.Enabled = true;
  77. }).SetUpdate(true).WaitForCompletion();
  78. }
  79. private void Close()
  80. {
  81. UnityEngine.Object.Destroy(R.Ui.CameraGO.GetComponent<AnalogTV>());
  82. this._panel.gameObject.SetActive(false);
  83. UIKeyInput.LoadHoveredObject();
  84. R.Mode.ExitMode(Mode.AllMode.UI);
  85. R.Ui.ShowUI(true);
  86. R.Audio.UnPauseBGM();
  87. }
  88. public YieldInstruction CloseWithAnimThenResume()
  89. {
  90. this.Enabled = false;
  91. AnalogTV analogTV = R.Ui.CameraGO.GetComponent<AnalogTV>();
  92. return DOTween.To(() => analogTV.Scale, delegate(float scale)
  93. {
  94. analogTV.Scale = scale;
  95. }, 0f, 0.5f).SetUpdate(true).OnComplete(delegate
  96. {
  97. this.Close();
  98. R.ResumeGame();
  99. this.Enabled = true;
  100. }).WaitForCompletion();
  101. }
  102. private void OnResumeClick()
  103. {
  104. if (!this.Enabled)
  105. {
  106. return;
  107. }
  108. UIKeyInput.OnPauseClick();
  109. }
  110. private void OnExitClick()
  111. {
  112. if (!this.Enabled)
  113. {
  114. return;
  115. }
  116. UIKeyInput.OnPauseClick();
  117. R.Ui.Reset();
  118. R.Player.Action.ChangeState(PlayerAction.StateEnum.Idle, 1f);
  119. R.Audio.StopVoiceOver();
  120. LevelManager.LoadLevelByGateId("ui_start", SceneGate.OpenType.None);
  121. }
  122. private void OnLevelSelect()
  123. {
  124. if (!this.Enabled)
  125. {
  126. return;
  127. }
  128. base.StartCoroutine(this.LevelSelectCoroutine());
  129. }
  130. private IEnumerator LevelSelectCoroutine()
  131. {
  132. R.Audio.StopVoiceOver();
  133. yield return UIKeyInput.OnPauseClick();
  134. R.Ui.LevelSelect.OpenWithAnim(true, true);
  135. yield break;
  136. }
  137. [SerializeField]
  138. private UIButton _resume;
  139. [SerializeField]
  140. private UIButton _exit;
  141. [SerializeField]
  142. private UIButton _levelSelect;
  143. [SerializeField]
  144. private UIPanel _panel;
  145. }