Ejemplo n.º 1
0
    // Loads data from disk.
    public void Load()
    {
        // Debug.Log("SaveManager - Entering load");
        // constructs absolute path to data file
        string saveGameDataPath = Application.dataPath + saveDirectory + saveGameData;

        // if file exists, proceed to load, otherwise open a new file
        if (File.Exists(saveGameDataPath))
        {
            string json = File.ReadAllText(saveGameDataPath);
            savedDataObject = JsonUtility.FromJson <SavedDataObject>(json);
            // Debug.Log("SaveManager - loaded data");
            playerScoreList = savedDataObject.playerScores;
            // foreach (PlayerScore score in playerScoreList) { Debug.Log("SaveManager - " + score.ToString()); }
        }
        else
        {
            // Debug.Log("SAVE FILE DOES NOT EXIST");
        }
        // retrieve username, if one exists, otherwise will default to "default"
        string userNameDataPath = Application.dataPath + saveDirectory + userNameFile;

        if (File.Exists(userNameDataPath))
        {
            userName = System.IO.File.ReadAllText(userNameDataPath);
            // Debug.Log("USERNAME: "******"SaveManager - Leaving load");
    }
Ejemplo n.º 2
0
    private void Load()
    {
        // Load
        string saveString = SaveSystem.Load();

        if (saveString != null)
        {
            Debug.Log("Loaded: " + saveString);

            SavedDataObject saveObject = JsonUtility.FromJson <SavedDataObject>(saveString);

            Debug.Log("highscore: " + saveObject.HighScore + ", coins: " + saveObject.Coins + ", diamonds: " + saveObject.Diamonds);
        }
        else
        {
            Debug.Log("No save");
        }
    }
Ejemplo n.º 3
0
    private void Save()
    {
        // Save
        int highScore = 15;
        int coins     = 10;
        int diamonds  = 20;

        SavedDataObject saveObject = new SavedDataObject
        {
            HighScore = highScore,
            Coins     = coins,
            Diamonds  = diamonds
        };
        string json = JsonUtility.ToJson(saveObject);

        SaveSystem.Save(json);

        Debug.Log("Saved successfuly");
    }