123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System.Collections.Generic;
- using JsonFx.Json;
- using UnityEngine;
- using System.Collections;
- public class TimerAd : MonoBehaviour
- {
- public int StartTimer = 7;
- public float Timer = 7;
- public UILabel timer;
- public UILabel text;
- public UILabel textFact;
- private const string URL = GameConstants.SERVER_BASE_URL + "Q&A/";
- public int CurLevel;
- public bool StartLevel;
- void Start ()
- {
- timer.text = "";
- text.text = "";
- }
- public void Init(bool startLevel = false)
- {
- StartLevel = startLevel;
- }
- void OnEnable()
- {
- //LoadQuestions();
- text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1);
- Timer = StartTimer;
- if (FlurryLogger.Instance)
- {
- FlurryLogger.Instance.ShowFullScreenAd();
- }
-
- }
- void Update ()
- {
- Timer = Timer - Time.deltaTime;
- if(Timer <= 0)
- {
- if (StartLevel)
- {
- MenuManager._instance.OnLeavingViewingAd();
- Timer = 100;
- NotificationCenter.Post(NotificationType.MenuTransition, MenuManager.MenuTransition.Continue);
- //NotificationCenter.Post(NotificationType.SelectNextLevel, CurLevel);
- }
- else
- {
- MenuManager._instance.OnLeavingViewingAd();
- }
-
-
-
- }
- timer.text = ((int)Timer).ToString();
- text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1);
- }
- private List<string> descriptionsDidYouKnow = new List<string>();
- private bool LoadQuestions()
- {
- if (descriptionsDidYouKnow.Count > 0)
- {
- textFact.text = descriptionsDidYouKnow[Random.Range(0, descriptionsDidYouKnow.Count-1)];
- return true;
- }
-
- bool success = false;
- string questionsAnswers = URL + "DidYouKnow.txt";
- WWW w = new WWW(questionsAnswers);
- while (!w.isDone)
- { }
- if (w.error != null)
- {
- Debug.Log(w.error);
- }
- else
- {
- try
- {
- var g = w.text.Split('\n');
- for (var s =0; s< g.Length;s++)
- {
- descriptionsDidYouKnow.Add(g[s]);
- }
- textFact.text = descriptionsDidYouKnow[Random.Range(0, descriptionsDidYouKnow.Count)];
- success = true;
- }
- catch (JsonDeserializationException ex)
- {
- Debug.Log(ex.Message);
- }
- }
- return success;
- }
-
- }
|