UIManager.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. using UnityEngine.UI;
  6. using System;
  7. public class UIManager : MonoBehaviour
  8. {
  9. public static UIManager Instance;
  10. public CanvasGroup SelectGenderPanel;
  11. public CanvasGroup GameWinPanel;
  12. public CanvasGroup MainMenuPanel;
  13. public CanvasGroup GameEndPanel;
  14. public InputField InputName;
  15. public GameObject TapToRaceButton;
  16. public GameObject ChangeNameAndCharacter;
  17. public CanvasGroup RacePanel;
  18. public GameObject LogoGame;
  19. public CanvasGroup GameOverPanel;
  20. public Text StageLabel;
  21. public Camera Camera;
  22. public float Timer;
  23. public float DefaultTimer =3;
  24. public Text TimerGameStart;
  25. public bool GameOver;
  26. public Text LevelGameEnd;
  27. public Text LevelGameOver;
  28. public Text CounterHearth;
  29. public Image BarHearthWays;
  30. //public void SetTimerKissTower()
  31. //{
  32. // throw new NotImplementedException();
  33. //}
  34. public CompleteCameraController CompleteCameraController;
  35. public string DefaultNameMale = "ADAM";
  36. public string DefaultNameFemale = "EMILI";
  37. public void OnClickMale()
  38. {
  39. NotificationCenter.Post(NotificationType.SetMale);
  40. Core.Instance.CurGender = Core.Gender.Male;
  41. Core.Instance.SetMale();
  42. CLoseGenderSelect();
  43. }
  44. public void GameEnd()
  45. {
  46. GameEndPanel.gameObject.SetActive(true);
  47. GameEndPanel.DOFade(1, 0.45f).OnComplete(() => {
  48. //SelectGenderPanel.gameObject.SetActive(false);
  49. });
  50. }
  51. public void OnClickSelect()
  52. {
  53. ChangeNameAndCharacter.gameObject.SetActive(false);
  54. TapToRaceButton.gameObject.SetActive(true);
  55. LevelManager.Instance.CurLevel.ArrowsChangePlayer.gameObject.SetActive(false);
  56. Core.Instance.PartPlayerInGame.gameObject.SetActive(true);
  57. Core.Instance.SetPlayer();
  58. Core.Instance.SetPlayerNewLevel();
  59. }
  60. public void UpdateGameplayMenu()
  61. {
  62. CounterHearth.text = Core.Instance.PlayerData.Heart.ToString();
  63. BarHearthWays.fillAmount = (float)Core.Instance.PlayerData.Heart/ (float)LevelManager.Instance.CurLevel.HeartController.ListHearth.Count;
  64. }
  65. // Update is called once per frame
  66. public void OnClickFemale()
  67. {
  68. NotificationCenter.Post(NotificationType.SetFemale);
  69. Core.Instance.CurGender = Core.Gender.Female;
  70. Core.Instance.SetFemale();
  71. CLoseGenderSelect();
  72. }
  73. public void CLoseGenderSelect()
  74. {
  75. switch(Core.Instance.CurGender)
  76. {
  77. case Core.Gender.Female:
  78. InputName.text = DefaultNameFemale;
  79. break;
  80. case Core.Gender.Male:
  81. InputName.text = DefaultNameMale;
  82. break;
  83. }
  84. SelectGenderPanel.DOFade(0,0.45f).OnComplete(()=> {
  85. SelectGenderPanel.gameObject.SetActive(false);
  86. });
  87. ChangeNameAndCharacter.gameObject.SetActive(true);
  88. TapToRaceButton.gameObject.SetActive(false);
  89. MainMenuPanel.gameObject.SetActive(true);
  90. MainMenuPanel.DOFade(1, 0.45f);
  91. LevelManager.Instance.CurLevel.ArrowsChangePlayer.gameObject.SetActive(true);
  92. Core.Instance.GetPlayerForSelecting(0, Core.Instance.CurGender);
  93. }
  94. public void TapToRace()
  95. {
  96. Core.Instance.IsGameMode = Core.StateModeGame.Menu;
  97. TimerGameStart.gameObject.SetActive(true);
  98. TapToRaceButton.gameObject.SetActive(false);
  99. Timer = DefaultTimer;
  100. Core.Instance.PlayerData.Heart = 0;
  101. Camera.GetComponent<CompleteCameraController>().enabled = true;
  102. MainMenuPanel.DOFade(0, 0.45f);
  103. LevelManager.Instance.CurLevel.ArrowsChangePlayer.gameObject.SetActive(false);
  104. RacePanel.gameObject.SetActive(true);
  105. RacePanel.DOFade(1, 0.45f);
  106. LevelManager.Instance.CurLevel.Logo.gameObject.SetActive(false);
  107. }
  108. //public void OnGameOver()
  109. //{
  110. // RacePanel.DOFade(0, 0.45f).OnComplete(() => {
  111. // SelectGenderPanel.gameObject.SetActive(false);
  112. // });
  113. // GameOverPanel.gameObject.SetActive(true);
  114. // GameOverPanel.DOFade(1, 0.45f);
  115. //}
  116. public void Start()
  117. {
  118. Instance = this;
  119. NotificationCenter.AddListener(OnGameOver,NotificationType.GameOver);
  120. NotificationCenter.AddListener(OnGameWin, NotificationType.GameWin);
  121. BarHearthWays.fillAmount = 0;
  122. }
  123. private void OnGameWin(Notification note)
  124. {
  125. RacePanel.DOFade(0, 0.45f).OnComplete(() => {
  126. //SelectGenderPanel.gameObject.SetActive(false);
  127. });
  128. GameWinPanel.gameObject.SetActive(true);
  129. GameWinPanel.DOFade(1, 0.45f);
  130. LevelManager.Instance.CurLevel.Logo.gameObject.SetActive(true);
  131. Core.Instance.IncreaseStagePlayer();
  132. LevelGameEnd.text = "Level " + Core.Instance.PlayerData.Stage.ToString();
  133. }
  134. private void OnGameOver(Notification note)
  135. {
  136. RacePanel.DOFade(0, 0.45f).OnComplete(() => {
  137. SelectGenderPanel.gameObject.SetActive(false);
  138. });
  139. GameOverPanel.gameObject.SetActive(true);
  140. LevelManager.Instance.CurLevel.Logo.gameObject.SetActive(true);
  141. GameOverPanel.DOFade(1, 0.45f);
  142. //LevelGameOver
  143. }
  144. public void OnDestroy()
  145. {
  146. NotificationCenter.RemoveListener(OnGameOver, NotificationType.GameOver);
  147. NotificationCenter.RemoveListener(OnGameWin, NotificationType.GameWin);
  148. }
  149. public void Update()
  150. {
  151. if (UIManager.Instance.RacePanel.gameObject.activeSelf && Core.Instance.IsGameMode != Core.StateModeGame.IsGameMode && Core.Instance.IsGameMode != Core.StateModeGame.Kiss && Core.Instance.IsGameMode != Core.StateModeGame.StartLevel)
  152. {
  153. Timer -= Time.deltaTime;
  154. if (Timer <= 0)
  155. {
  156. TimerGameStart.gameObject.SetActive(false);
  157. Timer = DefaultTimer;
  158. Core.Instance.IsGameMode = Core.StateModeGame.IsGameMode;
  159. NotificationCenter.Post(NotificationType.GameStart);
  160. }
  161. TimerGameStart.text = ((int)Timer).ToString();
  162. }
  163. }
  164. public void Restart()
  165. {
  166. GameOverPanel.DOFade(0, 0.45f).OnComplete(() => {
  167. GameOverPanel.gameObject.SetActive(false);
  168. ChangeNameAndCharacter.gameObject.SetActive(false);
  169. TapToRaceButton.gameObject.SetActive(true);
  170. MainMenuPanel.gameObject.SetActive(true);
  171. MainMenuPanel.DOFade(1, 0.45f);
  172. });
  173. Core.Instance.ResetPlayerPos();
  174. Core.Instance.ResetLevel();
  175. LevelManager.Instance.SetLevel(Core.Instance.PlayerData.Stage);
  176. Core.Instance.SetPlayerNewLevel();
  177. Core.Instance.PlayerGame.SwipeMove.enabled = true;
  178. CompleteCameraController.ResetCameraOnStartLeve();
  179. Core.Instance.IsGameMode = Core.StateModeGame.StartLevel;
  180. if (Core.Instance)
  181. {
  182. Core.Instance.LevelEnd = false;
  183. }
  184. //Core.Instance.IsGameMode = Core.StateModeGame.StartLevel;
  185. }
  186. public void ResetLevelData()
  187. {
  188. CounterHearth.text = "0";
  189. Core.Instance.PlayerData.Heart = 0;
  190. BarHearthWays.fillAmount = (float)Core.Instance.PlayerData.Heart / (float)LevelManager.Instance.CurLevel.HeartController.ListHearth.Count;
  191. }
  192. public void OnClickContinue()
  193. {
  194. GameWinPanel.DOFade(0, 0.45f).OnComplete(() => {
  195. GameWinPanel.gameObject.SetActive(false);
  196. ChangeNameAndCharacter.gameObject.SetActive(false);
  197. TapToRaceButton.gameObject.SetActive(true);
  198. MainMenuPanel.gameObject.SetActive(true);
  199. MainMenuPanel.DOFade(1, 0.45f);
  200. });
  201. Core.Instance.ResetPlayerPos();
  202. UIManager.Instance.GameOverPanel.gameObject.SetActive(false);
  203. Core.Instance.ResetLevel();
  204. LevelManager.Instance.NextLevel();
  205. Core.Instance.SetPlayerNewLevel();
  206. Core.Instance.PlayerGame.SwipeMove.enabled = true;
  207. CompleteCameraController.ResetCameraOnStartLeve();
  208. Core.Instance.IsGameMode = Core.StateModeGame.StartLevel;
  209. if (Core.Instance)
  210. {
  211. Core.Instance.LevelEnd = false;
  212. }
  213. }
  214. }