using System.Collections.Generic; using JsonFx.Json; using UnityEngine; using System.Collections; using TMPro; using ICTS.Localization; public class TimerAd : MonoBehaviour { public int StartTimer = 7; public float Timer = 7; public TextMeshProUGUI timer; public TextMeshProUGUI text; public TextMeshProUGUI 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; isEndTimerTick = false; //if (FlurryLogger.Instance) //{ // FlurryLogger.Instance.ShowFullScreenAd(); //} } private bool isEndTimerTick; void Update () { Timer = Timer - Time.deltaTime; if(Timer <= 0 && !isEndTimerTick) { //if (StartLevel) { MenuManager._instance.OnLeavingViewingAd(); //if (LevelsManager.Instance.CurrentLevelIndex == 0) { NotificationCenter.Post(NotificationType.CelebrityDisappeared); } isEndTimerTick = true; //NotificationCenter.Post(NotificationType.MenuTransition, MenuManager.MenuTransition.Continue); //NotificationCenter.Post(NotificationType.SelectNextLevel, CurLevel); } // else //{ // //if (LevelsManager.Instance.CurrentLevelIndex == 0) // { // NotificationCenter.Post(NotificationType.CelebrityDisappeared); // } // MenuManager._instance.OnLeavingViewingAd(); // //NotificationCenter.Post(NotificationType.MenuTransition, MenuManager.MenuTransition.Continue); //} } timer.text = ((int)Timer).ToString(); text.text = string.Format(Localization.instance.Get("ad.label.text"), LevelsManager.Instance.CurrentLevelIndex + 1); } private List descriptionsDidYouKnow = new List(); 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; } }