Esempio n. 1
0
    public static void Save(SpeedTapScoresLevel1 scores)
    {
        string dir = Application.persistentDataPath + directory;

        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }

        string json = JsonUtility.ToJson(scores);

        File.WriteAllText(dir + fileName, json);
    }
Esempio n. 2
0
    public static SpeedTapScoresLevel1 Load()
    {
        string fullPath        = Application.persistentDataPath + directory + fileName;
        SpeedTapScoresLevel1 s = new SpeedTapScoresLevel1();

        if (File.Exists(fullPath))
        {
            string json = File.ReadAllText(fullPath);
            s = JsonUtility.FromJson <SpeedTapScoresLevel1>(json);
        }
        else
        {
            // if file does not exist load default values into object
            Debug.Log("Save file does not exist");
            s.highScore1 = 0f;
            s.highScore2 = 0f;
            s.highScore3 = 0f;
        }
        return(s);
    }
Esempio n. 3
0
    /*------------ Save and Load Functions ------------*/
    private void SaveHighScore(float value)
    {
        /* Loading save data to object, if does not exist default values will be zero */
        score = SaveManager.Load();


        if (score.highScore1 > value || score.highScore1 == 0f)
        {
            // moving highscore values down and setting new high score
            score.highScore3 = score.highScore2;
            score.highScore2 = score.highScore1;
            score.highScore1 = value;

            // save updated scores to the save file
            SaveManager.Save(score);
            // Debug.Log(score.highScore1);
        }
        else if (score.highScore2 > value || score.highScore2 == 0f)
        {
            // moving highscore values down and setting new high score
            score.highScore3 = score.highScore2;
            score.highScore2 = value;

            // save updated scores to the save file
            SaveManager.Save(score);
            // Debug.Log(score.highScore2);
        }
        else if (score.highScore3 > value || score.highScore3 == 0f)
        {
            // moving highscore values down and setting new high score
            score.highScore3 = value;

            // save updated scores to the save file
            SaveManager.Save(score);
            //Debug.Log(score.highScore3);
        }


        // if the value is not greater than highscore 3 then it should not be added
    }