HighScoreUIManager.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4. using ICTS.Localization;
  5. /// <summary>
  6. /// We are reusing the same screen for How To Play, Game Over and viewing the scores.
  7. /// We just need to show different UI (buttons).
  8. /// This component is responsible for enabling/disabling the appropriate UI depending in which mode we are
  9. /// when displaying the scores.
  10. /// </summary>
  11. public class HighScoreUIManager : MonoBehaviour
  12. {
  13. #region Unity Singleton
  14. private static HighScoreUIManager _instance;
  15. public static HighScoreUIManager Instance
  16. {
  17. get
  18. {
  19. if (_instance == null)
  20. {
  21. _instance = FindObjectOfType(typeof(HighScoreUIManager)) as HighScoreUIManager;
  22. if (_instance == null)
  23. {
  24. Debug.LogError("No gameObject with HighScoreUIManager component exists. Make sure to create a gameObject with HighScoreUIManager component");
  25. }
  26. }
  27. return _instance;
  28. }
  29. }
  30. void Awake()
  31. {
  32. if (_instance != null && _instance != this)
  33. {
  34. Debug.LogWarning("HighScoreUIManager instance already exists on another gameObject. Destroying this gameObject HighScoreUIManager");
  35. Destroy(gameObject);
  36. return;
  37. }
  38. _instance = this;
  39. DontDestroyOnLoad(gameObject);
  40. }
  41. #endregion
  42. public enum ScoreViewMode
  43. {
  44. HowToPlay,
  45. GameOver,
  46. CombinedLeaderboard
  47. }
  48. [HideInInspector]
  49. public ScoreViewMode scoreViewMode;
  50. public GameObject gameOverUI;
  51. public GameObject howToPlay;
  52. public ScreenBase sponsorScreen;
  53. public GameObject[] miscellaneousButtons;
  54. public ButtonLevelSelector nextButton;
  55. public GameObject WaveButtonBuy;
  56. public GameObject ButtonArrow;
  57. public TextMeshProUGUI ButtonLabelNext;
  58. void OnEnable()
  59. {
  60. StartCoroutine(EnableUIAccordingToModeCoroutine());
  61. }
  62. IEnumerator EnableUIAccordingToModeCoroutine()
  63. {
  64. //Enable in the next frame, otherwise the anchors wouldn't have been set up yet
  65. yield return null;
  66. gameOverUI.SetActive(false);
  67. howToPlay.SetActive(false);
  68. ButtonArrow.SetActive(false);
  69. //Debug.Log("!!!!!!!!!!!scoreViewMode " + scoreViewMode);
  70. switch (scoreViewMode)
  71. {
  72. case ScoreViewMode.HowToPlay:
  73. howToPlay.SetActive(true);
  74. 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)
  75. {
  76. if(InventoryManager.Instance.GetItemCount(InventoryItem.specialwave) <= 1)
  77. {
  78. WaveButtonBuy.SetActive(true);
  79. }
  80. else
  81. {
  82. WaveButtonBuy.SetActive(false);
  83. }
  84. }
  85. else
  86. {
  87. WaveButtonBuy.SetActive(false);
  88. }
  89. EnableMiscellaneousButtons(true);
  90. break;
  91. case ScoreViewMode.GameOver:
  92. //NotificationCenter.Post(NotificationType.GameStart);
  93. Logger.LogFlurryEvent("Showed Fullscreen Ad");
  94. //MoPub.showBanner(false);
  95. //sponsorScreen.Show();
  96. gameOverUI.SetActive(true);
  97. ButtonLabelNext.text = string.Format(Localization.instance.Get("scores.next"), LevelsManager.Instance.CurrentLevelIndex + 2);
  98. //Danish Requirement: check for like page after game over
  99. if (FacebookHelper.Instance.IsLoggedIn())
  100. {
  101. FacebookHelper.Instance.QueryHasLikedPage();
  102. }
  103. var curLEvel = PlayerPrefs.GetInt("Level");
  104. /*curLEvel = curLEvel + 1;
  105. PlayerPrefs.SetInt("Level", curLEvel);*/
  106. //Debug.Log(PlayerPrefs.GetInt("Level"));
  107. if (LevelsManager.Instance.CurrentLevelIndex == LevelsManager.Instance.levels.Length - 1)
  108. {
  109. nextButton.gameObject.SetActive(false);
  110. } else
  111. {
  112. if (curLEvel > LevelsManager.Instance.CurrentLevelIndex+1)
  113. {
  114. Debug.Log("curLEvel > LevelsManager.Instance.CurrentLevelIndexs");
  115. nextButton.gameObject.SetActive(true);
  116. nextButton.levelIndex = LevelsManager.Instance.CurrentLevelIndex + 1;
  117. }
  118. else
  119. {
  120. nextButton.gameObject.SetActive(false);
  121. }
  122. }
  123. break;
  124. case ScoreViewMode.CombinedLeaderboard:
  125. EnableMiscellaneousButtons(false);
  126. ButtonArrow.SetActive(true);
  127. break;
  128. default:
  129. AVDebug.LogError("Score View Mode "+scoreViewMode+" not handled");
  130. break;
  131. }
  132. }
  133. void EnableMiscellaneousButtons(bool isEnabled)
  134. {
  135. /*for (int i = 0; i < miscellaneousButtons.Length; i++)
  136. {
  137. miscellaneousButtons[i].SetActive(isEnabled);
  138. }*/
  139. }
  140. }