void AddScoreRecord() { var questionsList = JsonConvert.DeserializeObject <List <Question> >(questionJsonResponse); var num_question = questionsList.Count; // add section score to the score record string currentWorld = ChooseWorld.world.ToString(); string currentSection = ChooseWorld.section.ToString(); string currentLevel = ChooseWorld.level.ToString(); Debug.Log("adding score to record for world: " + currentWorld + ", section: " + currentSection + ", level: " + currentLevel); WorldScoreRecord scoreRecord = ChooseWorld.scoreRecord; // get WorldScore object if (!scoreRecord.worldScores.ContainsKey(currentWorld)) { scoreRecord.worldScores.Add(currentWorld, new WorldScore()); } WorldScore worldScoreRecord = scoreRecord.worldScores[currentWorld]; // get sectionScore object if (!worldScoreRecord.sectionScores.ContainsKey(currentSection)) { worldScoreRecord.sectionScores.Add(currentSection, new SectionScore()); } SectionScore sectionScoreRecord = worldScoreRecord.sectionScores[currentSection]; // add the level score sectionScoreRecord.levelScores.Add(currentLevel, new LevelScore(num_question, sectionScore)); }
// Use this for initialization void Start() { int score = 0; int maxScore = 0; WorldScoreRecord scoreRecord = ChooseWorld.scoreRecord; // add up score foreach (KeyValuePair <string, WorldScore> worldItem in scoreRecord.worldScores) { WorldScore worldScore = worldItem.Value; foreach (KeyValuePair <string, SectionScore> sectionItem in worldScore.sectionScores) { SectionScore sectionScore = sectionItem.Value; foreach (KeyValuePair <string, LevelScore> levelItem in sectionScore.levelScores) { score = score + levelItem.Value.score; maxScore = maxScore + levelItem.Value.maxScore; } } } GameObject.Find("Canvas").transform .GetChild(0).gameObject.transform .GetChild(0) .GetComponent <Text>().text = "Total Score: " + score.ToString() + "/" + maxScore.ToString(); }
public void OpenPanel(string world) { if (Panel != null) { Panel.SetActive(true); // set title Panel.transform.GetChild(0).gameObject.GetComponent <Text>().text = "World " + world; // set all values to N/A for (int i = 1; i < 10; i++) { Panel.transform.GetChild(i + 6).gameObject.GetComponent <Text>().text = "N/A"; } // set score WorldScoreRecord scoreRecord = ChooseWorld.scoreRecord; if (scoreRecord.worldScores.ContainsKey(world)) { int worldIndex = int.Parse(world); if (scoreRecord.worldScores.ContainsKey(worldIndex.ToString())) { WorldScore worldScore = scoreRecord.worldScores[worldIndex.ToString()]; for (int sectionIndex = 1; sectionIndex < 4; sectionIndex++) { if (worldScore.sectionScores.ContainsKey(sectionIndex.ToString())) { SectionScore sectionScore = worldScore.sectionScores[sectionIndex.ToString()]; for (int levelIndex = 1; levelIndex < 4; levelIndex++) { if (sectionScore.levelScores.ContainsKey(levelIndex.ToString())) { LevelScore levelScore = sectionScore.levelScores[levelIndex.ToString()]; // set the text on the panel int componentIndex = (sectionIndex - 1) * 3 + levelIndex + 6; Panel.transform.GetChild(componentIndex).gameObject.GetComponent <Text>().text = levelScore.score.ToString() + "/" + levelScore.maxScore.ToString(); } } } } } } } }