TimerAd.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System.Collections.Generic;
  2. using JsonFx.Json;
  3. using UnityEngine;
  4. using System.Collections;
  5. using TMPro;
  6. using ICTS.Localization;
  7. public class TimerAd : MonoBehaviour
  8. {
  9. public int StartTimer = 7;
  10. public float Timer = 7;
  11. public TextMeshProUGUI timer;
  12. public TextMeshProUGUI text;
  13. public TextMeshProUGUI textFact;
  14. private const string URL = GameConstants.SERVER_BASE_URL + "Q&A/";
  15. public int CurLevel;
  16. public bool StartLevel;
  17. void Start ()
  18. {
  19. timer.text = "";
  20. text.text = "";
  21. }
  22. public void Init(bool startLevel = false)
  23. {
  24. StartLevel = startLevel;
  25. }
  26. void OnEnable()
  27. {
  28. //LoadQuestions();
  29. text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1);
  30. Timer = StartTimer;
  31. isEndTimerTick = false;
  32. //if (FlurryLogger.Instance)
  33. //{
  34. // FlurryLogger.Instance.ShowFullScreenAd();
  35. //}
  36. }
  37. private bool isEndTimerTick;
  38. void Update ()
  39. {
  40. Timer = Timer - Time.deltaTime;
  41. if(Timer <= 0 && !isEndTimerTick)
  42. {
  43. //if (StartLevel)
  44. {
  45. MenuManager._instance.OnLeavingViewingAd();
  46. //if (LevelsManager.Instance.CurrentLevelIndex == 0)
  47. {
  48. NotificationCenter.Post(NotificationType.CelebrityDisappeared);
  49. }
  50. isEndTimerTick = true;
  51. //NotificationCenter.Post(NotificationType.MenuTransition, MenuManager.MenuTransition.Continue);
  52. //NotificationCenter.Post(NotificationType.SelectNextLevel, CurLevel);
  53. }
  54. // else
  55. //{
  56. // //if (LevelsManager.Instance.CurrentLevelIndex == 0)
  57. // {
  58. // NotificationCenter.Post(NotificationType.CelebrityDisappeared);
  59. // }
  60. // MenuManager._instance.OnLeavingViewingAd();
  61. // //NotificationCenter.Post(NotificationType.MenuTransition, MenuManager.MenuTransition.Continue);
  62. //}
  63. }
  64. timer.text = ((int)Timer).ToString();
  65. text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1);
  66. }
  67. private List<string> descriptionsDidYouKnow = new List<string>();
  68. private bool LoadQuestions()
  69. {
  70. if (descriptionsDidYouKnow.Count > 0)
  71. {
  72. textFact.text = descriptionsDidYouKnow[Random.Range(0, descriptionsDidYouKnow.Count-1)];
  73. return true;
  74. }
  75. bool success = false;
  76. string questionsAnswers = URL + "DidYouKnow.txt";
  77. WWW w = new WWW(questionsAnswers);
  78. while (!w.isDone)
  79. { }
  80. if (w.error != null)
  81. {
  82. Debug.Log(w.error);
  83. }
  84. else
  85. {
  86. try
  87. {
  88. var g = w.text.Split('\n');
  89. for (var s =0; s< g.Length;s++)
  90. {
  91. descriptionsDidYouKnow.Add(g[s]);
  92. }
  93. textFact.text = descriptionsDidYouKnow[Random.Range(0, descriptionsDidYouKnow.Count)];
  94. success = true;
  95. }
  96. catch (JsonDeserializationException ex)
  97. {
  98. Debug.Log(ex.Message);
  99. }
  100. }
  101. return success;
  102. }
  103. }