123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System.Collections.Generic;
- using JsonFx.Json;
- using UnityEngine;
- using System.Collections;
- public class QuestionSelector : MonoBehaviour {
- public GameObject levelButtonPrefab;
- public GameObject parent;
- public List<ButtonQuestionSelector> ButtonLevelSelectors = new List<ButtonQuestionSelector>();
- const int OFFSET = 140;
- const int BUTTON_SPACING = 60;
- private const string URL = GameConstants.SERVER_BASE_URL + "Q&A/";
- /*void Start()
- {
- //PlayerPrefs.SetInt("Level", 1);
- int numOfLevels = LevelsManager.Instance.levels.Length;
- int posY = OFFSET;
- for (int i = 0; i < numOfLevels; i++)
- {
- Transform button = NGUITools.AddChild(parent, levelButtonPrefab).transform;
- Vector3 pos = new Vector3(0, posY, -8);
- button.localPosition = pos;
- posY -= BUTTON_SPACING;
- var label = button.GetComponentInChildren<UILabel>();
- label.text = string.Format(Localization.instance.Get("levelButton.text"), i + 1); //+1 since players prefer 1-based
- ButtonQuestionSelector buttonLevelSelector = button.GetComponent<ButtonQuestionSelector>();
- //buttonLevelSelector.levelIndex = i;
- ButtonLevelSelectors.Add(buttonLevelSelector);
- }
- //ActivateCountButtonLevel();
- }*/
- void OnEnable()
- {
- LoadQuestions();
- }
- private bool LoadQuestions()
- {
- bool success = false;
- string questionsAnswers = URL + "QuestionsAnswers.txt";
- WWW w = new WWW(questionsAnswers);
- while (!w.isDone)
- { }
- if (w.error != null)
- {
- Debug.Log(w.error);
- }
- else
- {
- try
- {
- Debug.Log(w.text);
- //Leaderboard[] _leaderboards = JsonReader.Deserialize<Leaderboard[]>(w.text);
- //_leaderboards.Clear();
- //_leaderboards.AddRange(leaderboards);
- success = true;
- }
- catch (JsonDeserializationException ex)
- {
- Debug.Log(ex.Message);
- }
- }
- return success;
- }
- /*void ActivateCountButtonLevel()
- {
- int playerLevel = PlayerPrefs.GetInt("Level");
- if (playerLevel == 0)
- {
- PlayerPrefs.SetInt("Level", 1);
- }
- playerLevel = PlayerPrefs.GetInt("Level");
- //Debug.Log(playerLevel);
- for (int i = 0; i < ButtonLevelSelectors.Count; i++)
- {
- if (i > playerLevel - 1)
- {
- ButtonLevelSelectors[i].ButtonWithTwoState.DeactivateButton();
- }
- else
- {
- ButtonLevelSelectors[i].ButtonWithTwoState.ActivateButton();
- }
- }
- }*/
- /*void OnEnable()
- {
- //Debug.Log("ActivateCountButtonLevel");
- ActivateCountButtonLevel();
- }*/
- }
|