QuestionSelector.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Collections.Generic;
  2. using JsonFx.Json;
  3. using UnityEngine;
  4. using System.Collections;
  5. public class QuestionSelector : MonoBehaviour {
  6. public GameObject levelButtonPrefab;
  7. public GameObject parent;
  8. public List<ButtonQuestionSelector> ButtonLevelSelectors = new List<ButtonQuestionSelector>();
  9. const int OFFSET = 140;
  10. const int BUTTON_SPACING = 60;
  11. private const string URL = GameConstants.SERVER_BASE_URL + "Q&A/";
  12. /*void Start()
  13. {
  14. //PlayerPrefs.SetInt("Level", 1);
  15. int numOfLevels = LevelsManager.Instance.levels.Length;
  16. int posY = OFFSET;
  17. for (int i = 0; i < numOfLevels; i++)
  18. {
  19. Transform button = NGUITools.AddChild(parent, levelButtonPrefab).transform;
  20. Vector3 pos = new Vector3(0, posY, -8);
  21. button.localPosition = pos;
  22. posY -= BUTTON_SPACING;
  23. var label = button.GetComponentInChildren<UILabel>();
  24. label.text = string.Format(Localization.instance.Get("levelButton.text"), i + 1); //+1 since players prefer 1-based
  25. ButtonQuestionSelector buttonLevelSelector = button.GetComponent<ButtonQuestionSelector>();
  26. //buttonLevelSelector.levelIndex = i;
  27. ButtonLevelSelectors.Add(buttonLevelSelector);
  28. }
  29. //ActivateCountButtonLevel();
  30. }*/
  31. void OnEnable()
  32. {
  33. LoadQuestions();
  34. }
  35. private bool LoadQuestions()
  36. {
  37. bool success = false;
  38. string questionsAnswers = URL + "QuestionsAnswers.txt";
  39. WWW w = new WWW(questionsAnswers);
  40. while (!w.isDone)
  41. { }
  42. if (w.error != null)
  43. {
  44. Debug.Log(w.error);
  45. }
  46. else
  47. {
  48. try
  49. {
  50. Debug.Log(w.text);
  51. //Leaderboard[] _leaderboards = JsonReader.Deserialize<Leaderboard[]>(w.text);
  52. //_leaderboards.Clear();
  53. //_leaderboards.AddRange(leaderboards);
  54. success = true;
  55. }
  56. catch (JsonDeserializationException ex)
  57. {
  58. Debug.Log(ex.Message);
  59. }
  60. }
  61. return success;
  62. }
  63. /*void ActivateCountButtonLevel()
  64. {
  65. int playerLevel = PlayerPrefs.GetInt("Level");
  66. if (playerLevel == 0)
  67. {
  68. PlayerPrefs.SetInt("Level", 1);
  69. }
  70. playerLevel = PlayerPrefs.GetInt("Level");
  71. //Debug.Log(playerLevel);
  72. for (int i = 0; i < ButtonLevelSelectors.Count; i++)
  73. {
  74. if (i > playerLevel - 1)
  75. {
  76. ButtonLevelSelectors[i].ButtonWithTwoState.DeactivateButton();
  77. }
  78. else
  79. {
  80. ButtonLevelSelectors[i].ButtonWithTwoState.ActivateButton();
  81. }
  82. }
  83. }*/
  84. /*void OnEnable()
  85. {
  86. //Debug.Log("ActivateCountButtonLevel");
  87. ActivateCountButtonLevel();
  88. }*/
  89. }