Basic Saving and Loading

Save Game Free provides a simple and consistent API that lets you save and load data easily.

Saving an integer data type:

SaveGame.Save<int>("score", score);

Loading an integer data type:

int score = SaveGame.Load<int>("score");

Here is a simple usage of Save Game Free for saving and loading data:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using BayatGames.SaveGameFree;
 
public class SimpleUsage : MonoBehaviour {
 
    public int score;
 
    void Start () {
 
        // Saving the data
        SaveGame.Save<int> ( "score", score );
    }
 
}

As you can see you can use SaveGame API to save and load game data easily,  now let us save a simple String value:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using BayatGames.SaveGameFree;
 
public class SimpleUsage : MonoBehaviour {
 
    public string username;
 
    void Start () {
 
        // Saving the data
        SaveGame.Save<string> ( "username", username );
    }
 
}

So, here is saving and loading a collection of Data:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using BayatGames.SaveGameFree;
 
public class SimpleUsage : MonoBehaviour {
 
    void Start () {
        Dictionary<string, int> playerScores = new Dictionary<string, int> ();
        playerScores.Add ( "John", 100 );
        playerScores.Add ( "Jack", 200 );
 
        // Saving the data
        SaveGame.Save<Dictionary<string, int>> ( "playerScores", playerScores );
    }
 
}

Now, let us save a Custom Data class:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using BayatGames.SaveGameFree;
 
public class SimpleUsage : MonoBehaviour {
 
    public class PlayerData {
        public int score;
        public string name;
    }
 
    void Start () {
        PlayerData data = new PlayerData ();
        data.score = 453;
        data.name = "John";
 
        // Saving the data
        SaveGame.Save<PlayerData> ( "playerData", data );
    }
 
}