public void PianoActionRecieved(PianoDriver.KeyNote key, bool action) { if (action == true) //If the key is being pressed { switch (key) { case PianoDriver.KeyNote.DO: GameObject.FindGameObjectWithTag("AppManager").GetComponent <StageManager>().ChangeState(StageManager.State.MenuGame); Destroy(this.gameObject); break; case PianoDriver.KeyNote.SOL: if (GameObject.FindGameObjectWithTag("AppManager").GetComponent <StageManager>().AudioNotes) { GameObject.FindGameObjectWithTag("AppManager").GetComponent <StageManager>().AudioNotes = false; Audio_info.text = "\nU\nN\nM\nU\nT\nE\n\nN\nO\nT\nE\nS"; } else { GameObject.FindGameObjectWithTag("AppManager").GetComponent <StageManager>().AudioNotes = true; Audio_info.text = "M\nU\nT\nE\n\nN\nO\nT\nE\nS"; } break; case PianoDriver.KeyNote.DO2: JsonManagerScore.InitLvlJSON(); GameObject.FindGameObjectWithTag("AppManager").GetComponent <StageManager>().ChangeState(StageManager.State.MenuGame); Destroy(this.gameObject); break; } } }
// Use this for initialization void Start() { LvlJson lvlJson = null; if (Level_Number != 0) { lvlJson = JsonManagerScore.ReadLvlJSON(Level_Number); } Level_Info.text = "LEVEL " + Level_Number; if (lvlJson != null) { this.GetComponent <StarDisplay>().DisplayStars(lvlJson.Stars); Score_Info.text = "Score: " + lvlJson.Score; //Calculate next star if (lvlJson.Stars != 0) { if (lvlJson.Stars == 5) { NextStar_Info.text = "Level completed!"; } else { NextStar_Info.text = "\nNext in: " + lvlJson.LimitStarts[lvlJson.Stars]; Instantiate(ModelStar, positionModelStart); } } } }
// Use this for initialization void Start() { string path = Path.Combine(Application.persistentDataPath, "score.json"); Debug.Log(path); if (!File.Exists(path)) { JsonManagerScore.InitLvlJSON(); } }
public static bool StoreLvlJSON(LvlJson aux) { //READ JSON bool inside = false; bool new_record = false; List <LvlJson> lvls = null; try { lvls = JsonManagerScore.ReadLvlJSON(); //SEARCH LVL foreach (LvlJson lvl in lvls) { //UPDATE IF IS CREATED if (lvl.Lvl == aux.Lvl) { if (lvl.Score < aux.Score) // IF NEW RECORD { lvl.Score = aux.Score; if (lvl.Stars < aux.Stars) //IF NEW STAR OBTAINED { lvl.Stars = aux.Stars; lvl.LimitStarts = aux.LimitStarts; } new_record = true; } inside = true; } } } catch { } //CREATE IF IS NEW if (!inside) { if (lvls == null) { lvls = new List <LvlJson>(); } lvls.Add(aux); new_record = true; } //WRITE FILE string path = Path.Combine(Application.persistentDataPath, "score.json"); string json = JsonConvert.SerializeObject(lvls.ToArray()); using (TextWriter writer = File.CreateText(path)) { writer.Write(json); } return(new_record); }
private void UpdateMeasure() { actualMeasure++; if (actualMeasure > TotalMeasures) //IF THE LEVEL ENDS { GameObject lvl_aux = Instantiate(lvl_ends); bool record = false; if (Level != 0) { int stars = calculateStars(); record = JsonManagerScore.StoreLvlJSON(new LvlJson(Level, actualScore, stars, StarsLimits.ToArray())); lvl_aux.GetComponent <StarDisplayEffect>().DisplayStars(stars); } //STORE RESULT lvl_aux.GetComponent <FinalResult>().scoreObtained = actualScore; lvl_aux.GetComponent <FinalResult>().New_record = record; lvl_aux.name = lvl_aux.transform.name.Replace("(Clone)", ""); lvl_aux.transform.position = GameObject.FindGameObjectWithTag("Piano").GetComponent <Transform>().position; lvl_aux.transform.rotation = GameObject.FindGameObjectWithTag("Piano").GetComponent <Transform>().rotation; Destroy(this.transform.parent.gameObject); } }