123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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<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;
- }
-
- }
|