TimerAd.cs 2.3 KB

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