TimerAd.cs 2.4 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. KHD.FlurryAnalyticsTest.instance.ShowFullScreenAd();
  30. }
  31. void Update ()
  32. {
  33. Timer = Timer - Time.deltaTime;
  34. if(Timer <= 0)
  35. {
  36. if (StartLevel)
  37. {
  38. DownloadImageFromServer.Instance.GetTexture();
  39. MenuManager._instance.OnLeavingViewingAd();
  40. Timer = 100;
  41. NotificationCenter.Post(NotificationType.MenuTransition, MenuManager.MenuTransition.Continue);
  42. //NotificationCenter.Post(NotificationType.SelectNextLevel, CurLevel);
  43. }
  44. else
  45. {
  46. MenuManager._instance.OnLeavingViewingAd();
  47. DownloadImageFromServer.Instance.GetTexture();
  48. }
  49. }
  50. timer.text = ((int)Timer).ToString();
  51. text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1);
  52. }
  53. private List<string> descriptionsDidYouKnow = new List<string>();
  54. private bool LoadQuestions()
  55. {
  56. if (descriptionsDidYouKnow.Count > 0)
  57. {
  58. textFact.text = descriptionsDidYouKnow[Random.Range(0, descriptionsDidYouKnow.Count-1)];
  59. return true;
  60. }
  61. bool success = false;
  62. string questionsAnswers = URL + "DidYouKnow.txt";
  63. WWW w = new WWW(questionsAnswers);
  64. while (!w.isDone)
  65. { }
  66. if (w.error != null)
  67. {
  68. Debug.Log(w.error);
  69. }
  70. else
  71. {
  72. try
  73. {
  74. var g = w.text.Split('\n');
  75. for (var s =0; s< g.Length;s++)
  76. {
  77. descriptionsDidYouKnow.Add(g[s]);
  78. }
  79. textFact.text = descriptionsDidYouKnow[Random.Range(0, descriptionsDidYouKnow.Count)];
  80. success = true;
  81. }
  82. catch (JsonDeserializationException ex)
  83. {
  84. Debug.Log(ex.Message);
  85. }
  86. }
  87. return success;
  88. }
  89. }