Exemplo n.º 1
0
    public void SaveScores(string saveFileName)
    {
        MinigameHighScoreSaveData savescores = new MinigameHighScoreSaveData();

        savescores.scores = inspectorScores;
        string dataAsJson = JsonUtility.ToJson(savescores);
        string filePath   = Path.Combine(Application.streamingAssetsPath, saveFileName);

        File.WriteAllText(filePath, dataAsJson);
    }
Exemplo n.º 2
0
    public MinigameHighscore[] GetScoresArray()
    {
        //MinigameHighscore[] scoresarray = new MinigameHighscore[numScores];
        //scores.CopyTo(scoresarray, 0);
        //return scoresarray;
        SaveScores(saveFileName);
        MinigameHighScoreSaveData load = LoadScores(saveFileName);

        if (load != null)
        {
            return(load.scores);
        }
        else
        {
            return(inspectorScores);
        }
    }
Exemplo n.º 3
0
    public MinigameHighScoreSaveData LoadScores(string saveFileName)
    {
        MinigameHighScoreSaveData loadedData = null;
        string filePath = Path.Combine(Application.streamingAssetsPath, saveFileName);

        if (File.Exists(filePath))
        {
            // Read the json from the file into a string
            string dataAsJson = File.ReadAllText(filePath);
            // Pass the json to JsonUtility, and tell it to create a GameData object from it
            loadedData = JsonUtility.FromJson <MinigameHighScoreSaveData>(dataAsJson);
        }
        else
        {
            Debug.LogError("Cannot load game data!");
        }
        return(loadedData);
    }
Exemplo n.º 4
0
 void OnEnable()
 {
     Debug.Log("Minigame Save Data OnEnabled called.");
     //deserialise the scores?
     if (scores == null)
     {
         Debug.Log("Reinitialising scores");
         MinigameHighScoreSaveData loadedScores = LoadScores(saveFileName);
         if (loadedScores != null)
         {
             InitScores(loadedScores.scores);
         }
         else
         {
             InitScores(null);
         }
     }
 }