public static void SaveGame(SavedGame saveData, int saveSlot)
    {
        FileStream file = null;

        try
        {
            BinaryFormatter bf = new BinaryFormatter();
            file = File.Create(Application.persistentDataPath + "/save" + saveSlot + ".dat");
            VersionedSave versionedSave = new VersionedSave();
            versionedSave.saveData = saveData;
            bf.Serialize(file, versionedSave);
        }
        catch (Exception e)
        {
            if (e != null)
            {
                // unable to save
            }
        }
        finally
        {
            if (file != null)
            {
                file.Close();
            }
        }
    }
    public static SavedGame LoadGame(int saveSlot)
    {
        FileStream file     = null;
        SavedGame  saveData = null;

        try
        {
            BinaryFormatter bf = new BinaryFormatter();
            file = File.Open(Application.persistentDataPath + "/save" + saveSlot + ".dat", FileMode.Open);
            VersionedSave versionedSave = (VersionedSave)bf.Deserialize(file);
            saveData = VersionedSave.deversion(versionedSave);
        }
        catch (Exception e)
        {
            if (e != null)
            {
                // unable to load
            }
        }
        finally
        {
            if (file != null)
            {
                file.Close();
            }
        }
        return(saveData);
    }
 public static SavedGame deversion(VersionedSave versionedSave)
 {
     // if versionedSave.version is less than the current version, convert it here
     return((SavedGame)versionedSave.saveData);
 }