123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- using UnityEngine.UI;
- using System;
- public class UIManager : MonoBehaviour
- {
- public static UIManager Instance;
- public CanvasGroup SelectGenderPanel;
- public CanvasGroup GameWinPanel;
- public CanvasGroup MainMenuPanel;
- public CanvasGroup GameEndPanel;
- public InputField InputName;
- public GameObject TapToRaceButton;
- public GameObject ChangeNameAndCharacter;
- public CanvasGroup RacePanel;
- public GameObject LogoGame;
- public CanvasGroup GameOverPanel;
- public Text StageLabel;
-
- public Camera Camera;
- public float Timer;
- public float DefaultTimer =3;
- public Text TimerGameStart;
- public bool GameOver;
- public Text LevelGameEnd;
- public Text LevelGameOver;
- public Text CounterHearth;
- public Image BarHearthWays;
- //public void SetTimerKissTower()
- //{
- // throw new NotImplementedException();
- //}
- public CompleteCameraController CompleteCameraController;
- public string DefaultNameMale = "ADAM";
- public string DefaultNameFemale = "EMILI";
- public void OnClickMale()
- {
- NotificationCenter.Post(NotificationType.SetMale);
- Core.Instance.CurGender = Core.Gender.Male;
- Core.Instance.SetMale();
- CLoseGenderSelect();
- }
- public void GameEnd()
- {
- GameEndPanel.gameObject.SetActive(true);
- GameEndPanel.DOFade(1, 0.45f).OnComplete(() => {
- //SelectGenderPanel.gameObject.SetActive(false);
- });
-
- }
- public void OnClickSelect()
- {
- ChangeNameAndCharacter.gameObject.SetActive(false);
- TapToRaceButton.gameObject.SetActive(true);
- LevelManager.Instance.CurLevel.ArrowsChangePlayer.gameObject.SetActive(false);
- Core.Instance.PartPlayerInGame.gameObject.SetActive(true);
- Core.Instance.SetPlayer();
- Core.Instance.SetPlayerNewLevel();
- }
- public void UpdateGameplayMenu()
- {
- CounterHearth.text = Core.Instance.PlayerData.Heart.ToString();
- BarHearthWays.fillAmount = (float)Core.Instance.PlayerData.Heart/ (float)LevelManager.Instance.CurLevel.HeartController.ListHearth.Count;
- }
- // Update is called once per frame
- public void OnClickFemale()
- {
- NotificationCenter.Post(NotificationType.SetFemale);
- Core.Instance.CurGender = Core.Gender.Female;
- Core.Instance.SetFemale();
- CLoseGenderSelect();
- }
- public void CLoseGenderSelect()
- {
- switch(Core.Instance.CurGender)
- {
- case Core.Gender.Female:
- InputName.text = DefaultNameFemale;
- break;
- case Core.Gender.Male:
- InputName.text = DefaultNameMale;
- break;
- }
- SelectGenderPanel.DOFade(0,0.45f).OnComplete(()=> {
- SelectGenderPanel.gameObject.SetActive(false);
- });
- ChangeNameAndCharacter.gameObject.SetActive(true);
- TapToRaceButton.gameObject.SetActive(false);
- MainMenuPanel.gameObject.SetActive(true);
- MainMenuPanel.DOFade(1, 0.45f);
- LevelManager.Instance.CurLevel.ArrowsChangePlayer.gameObject.SetActive(true);
- Core.Instance.GetPlayerForSelecting(0, Core.Instance.CurGender);
- }
- public void TapToRace()
- {
- Core.Instance.IsGameMode = Core.StateModeGame.Menu;
- TimerGameStart.gameObject.SetActive(true);
- TapToRaceButton.gameObject.SetActive(false);
- Timer = DefaultTimer;
- Core.Instance.PlayerData.Heart = 0;
- Camera.GetComponent<CompleteCameraController>().enabled = true;
- MainMenuPanel.DOFade(0, 0.45f);
- LevelManager.Instance.CurLevel.ArrowsChangePlayer.gameObject.SetActive(false);
- RacePanel.gameObject.SetActive(true);
- RacePanel.DOFade(1, 0.45f);
-
- LevelManager.Instance.CurLevel.Logo.gameObject.SetActive(false);
- }
- //public void OnGameOver()
- //{
- // RacePanel.DOFade(0, 0.45f).OnComplete(() => {
- // SelectGenderPanel.gameObject.SetActive(false);
- // });
- // GameOverPanel.gameObject.SetActive(true);
- // GameOverPanel.DOFade(1, 0.45f);
- //}
- public void Start()
- {
- Instance = this;
- NotificationCenter.AddListener(OnGameOver,NotificationType.GameOver);
- NotificationCenter.AddListener(OnGameWin, NotificationType.GameWin);
- BarHearthWays.fillAmount = 0;
- }
- private void OnGameWin(Notification note)
- {
- RacePanel.DOFade(0, 0.45f).OnComplete(() => {
- //SelectGenderPanel.gameObject.SetActive(false);
- });
- GameWinPanel.gameObject.SetActive(true);
- GameWinPanel.DOFade(1, 0.45f);
- LevelManager.Instance.CurLevel.Logo.gameObject.SetActive(true);
- Core.Instance.IncreaseStagePlayer();
- LevelGameEnd.text = "Level " + Core.Instance.PlayerData.Stage.ToString();
- }
- private void OnGameOver(Notification note)
- {
- RacePanel.DOFade(0, 0.45f).OnComplete(() => {
- SelectGenderPanel.gameObject.SetActive(false);
- });
- GameOverPanel.gameObject.SetActive(true);
- LevelManager.Instance.CurLevel.Logo.gameObject.SetActive(true);
- GameOverPanel.DOFade(1, 0.45f);
- //LevelGameOver
- }
- public void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnGameOver, NotificationType.GameOver);
- NotificationCenter.RemoveListener(OnGameWin, NotificationType.GameWin);
- }
- public void Update()
- {
- if (UIManager.Instance.RacePanel.gameObject.activeSelf && Core.Instance.IsGameMode != Core.StateModeGame.IsGameMode && Core.Instance.IsGameMode != Core.StateModeGame.Kiss && Core.Instance.IsGameMode != Core.StateModeGame.StartLevel)
- {
- Timer -= Time.deltaTime;
- if (Timer <= 0)
- {
- TimerGameStart.gameObject.SetActive(false);
- Timer = DefaultTimer;
- Core.Instance.IsGameMode = Core.StateModeGame.IsGameMode;
- NotificationCenter.Post(NotificationType.GameStart);
- }
- TimerGameStart.text = ((int)Timer).ToString();
- }
- }
- public void Restart()
- {
- GameOverPanel.DOFade(0, 0.45f).OnComplete(() => {
- GameOverPanel.gameObject.SetActive(false);
- ChangeNameAndCharacter.gameObject.SetActive(false);
- TapToRaceButton.gameObject.SetActive(true);
- MainMenuPanel.gameObject.SetActive(true);
- MainMenuPanel.DOFade(1, 0.45f);
- });
- Core.Instance.ResetPlayerPos();
- Core.Instance.ResetLevel();
- LevelManager.Instance.SetLevel(Core.Instance.PlayerData.Stage);
- Core.Instance.SetPlayerNewLevel();
- Core.Instance.PlayerGame.SwipeMove.enabled = true;
- CompleteCameraController.ResetCameraOnStartLeve();
- Core.Instance.IsGameMode = Core.StateModeGame.StartLevel;
- if (Core.Instance)
- {
- Core.Instance.LevelEnd = false;
- }
- //Core.Instance.IsGameMode = Core.StateModeGame.StartLevel;
- }
- public void ResetLevelData()
- {
- CounterHearth.text = "0";
- Core.Instance.PlayerData.Heart = 0;
- BarHearthWays.fillAmount = (float)Core.Instance.PlayerData.Heart / (float)LevelManager.Instance.CurLevel.HeartController.ListHearth.Count;
- }
- public void OnClickContinue()
- {
- GameWinPanel.DOFade(0, 0.45f).OnComplete(() => {
- GameWinPanel.gameObject.SetActive(false);
- ChangeNameAndCharacter.gameObject.SetActive(false);
- TapToRaceButton.gameObject.SetActive(true);
- MainMenuPanel.gameObject.SetActive(true);
- MainMenuPanel.DOFade(1, 0.45f);
- });
- Core.Instance.ResetPlayerPos();
- UIManager.Instance.GameOverPanel.gameObject.SetActive(false);
- Core.Instance.ResetLevel();
- LevelManager.Instance.NextLevel();
-
- Core.Instance.SetPlayerNewLevel();
- Core.Instance.PlayerGame.SwipeMove.enabled = true;
- CompleteCameraController.ResetCameraOnStartLeve();
- Core.Instance.IsGameMode = Core.StateModeGame.StartLevel;
- if (Core.Instance)
- {
- Core.Instance.LevelEnd = false;
- }
- }
- }
|