123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using UnityEngine;
- using System.Collections;
- using TMPro;
- using ICTS.Localization;
- /// <summary>
- /// We are reusing the same screen for How To Play, Game Over and viewing the scores.
- /// We just need to show different UI (buttons).
- /// This component is responsible for enabling/disabling the appropriate UI depending in which mode we are
- /// when displaying the scores.
- /// </summary>
- public class HighScoreUIManager : MonoBehaviour
- {
- #region Unity Singleton
- private static HighScoreUIManager _instance;
- public static HighScoreUIManager Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = FindObjectOfType(typeof(HighScoreUIManager)) as HighScoreUIManager;
- if (_instance == null)
- {
- Debug.LogError("No gameObject with HighScoreUIManager component exists. Make sure to create a gameObject with HighScoreUIManager component");
- }
- }
- return _instance;
- }
- }
- void Awake()
- {
- if (_instance != null && _instance != this)
- {
- Debug.LogWarning("HighScoreUIManager instance already exists on another gameObject. Destroying this gameObject HighScoreUIManager");
- Destroy(gameObject);
- return;
- }
- _instance = this;
- DontDestroyOnLoad(gameObject);
- }
- #endregion
- public enum ScoreViewMode
- {
- HowToPlay,
- GameOver,
- CombinedLeaderboard
- }
- [HideInInspector]
- public ScoreViewMode scoreViewMode;
- public GameObject gameOverUI;
- public GameObject howToPlay;
- public ScreenBase sponsorScreen;
- public GameObject[] miscellaneousButtons;
- public ButtonLevelSelector nextButton;
- public GameObject WaveButtonBuy;
- public GameObject ButtonArrow;
- public TextMeshProUGUI ButtonLabelNext;
- void OnEnable()
- {
- StartCoroutine(EnableUIAccordingToModeCoroutine());
-
- }
- IEnumerator EnableUIAccordingToModeCoroutine()
- {
- //Enable in the next frame, otherwise the anchors wouldn't have been set up yet
- yield return null;
- gameOverUI.SetActive(false);
- howToPlay.SetActive(false);
- ButtonArrow.SetActive(false);
- //Debug.Log("!!!!!!!!!!!scoreViewMode " + scoreViewMode);
- switch (scoreViewMode)
- {
- case ScoreViewMode.HowToPlay:
- howToPlay.SetActive(true);
- if (LevelsManager.Instance.CurrentLevelIndex + 1 == 1 || LevelsManager.Instance.CurrentLevelIndex + 1 == 3 || LevelsManager.Instance.CurrentLevelIndex + 1 == 5 || LevelsManager.Instance.CurrentLevelIndex + 1 == 7 || LevelsManager.Instance.CurrentLevelIndex + 1 == 6 || LevelsManager.Instance.CurrentLevelIndex + 1 == 8 || LevelsManager.Instance.CurrentLevelIndex + 1 == 9)
- {
- if(InventoryManager.Instance.GetItemCount(InventoryItem.specialwave) <= 1)
- {
- WaveButtonBuy.SetActive(true);
- }
- else
- {
- WaveButtonBuy.SetActive(false);
-
- }
- }
- else
- {
- WaveButtonBuy.SetActive(false);
- }
- EnableMiscellaneousButtons(true);
- break;
- case ScoreViewMode.GameOver:
- //NotificationCenter.Post(NotificationType.GameStart);
- Logger.LogFlurryEvent("Showed Fullscreen Ad");
- //MoPub.showBanner(false);
- //sponsorScreen.Show();
- gameOverUI.SetActive(true);
-
- ButtonLabelNext.text = string.Format(Localization.instance.Get("scores.next"), LevelsManager.Instance.CurrentLevelIndex + 2);
- //Danish Requirement: check for like page after game over
- if (FacebookHelper.Instance.IsLoggedIn())
- {
- FacebookHelper.Instance.QueryHasLikedPage();
- }
- var curLEvel = PlayerPrefs.GetInt("Level");
- /*curLEvel = curLEvel + 1;
- PlayerPrefs.SetInt("Level", curLEvel);*/
- //Debug.Log(PlayerPrefs.GetInt("Level"));
-
- if (LevelsManager.Instance.CurrentLevelIndex == LevelsManager.Instance.levels.Length - 1)
- {
- nextButton.gameObject.SetActive(false);
- } else
- {
- if (curLEvel > LevelsManager.Instance.CurrentLevelIndex+1)
- {
- Debug.Log("curLEvel > LevelsManager.Instance.CurrentLevelIndexs");
- nextButton.gameObject.SetActive(true);
- nextButton.levelIndex = LevelsManager.Instance.CurrentLevelIndex + 1;
- }
- else
- {
- nextButton.gameObject.SetActive(false);
- }
- }
- break;
- case ScoreViewMode.CombinedLeaderboard:
- EnableMiscellaneousButtons(false);
- ButtonArrow.SetActive(true);
- break;
- default:
- AVDebug.LogError("Score View Mode "+scoreViewMode+" not handled");
- break;
- }
- }
- void EnableMiscellaneousButtons(bool isEnabled)
- {
- /*for (int i = 0; i < miscellaneousButtons.Length; i++)
- {
- miscellaneousButtons[i].SetActive(isEnabled);
- }*/
- }
- }
|