Hello, I am creating a save system for games and would like to know how I can generate a list from a BinaryFormatter
object? this file is formed from 3 information, and would like to generate a list with these values, follow the codes:
Create the file:
public void Save(string userName, int HighScore)
{
BinaryFormatter bf = new BinaryFormatter();
FileStream _file = File.Open(Application.dataPath + "/Save" + _filename, FileMode.Append);
PlayerData _data = new PlayerData();
_data.playername = userName;
_data.typeScore = "points";
_data.highscore = HighScore;
bf.Serialize(_file, _data);
_file.Close();
Debug.Log("Save Criado!");
}
and to load it:
public void Load()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream _file = File.Open(Application.dataPath + "/Save" + _filename, FileMode.Open);
PlayerData _data = (PlayerData)bf.Deserialize(_file);
infoData = _data;
_file.Close();
Debug.Log(_data);
}
I wanted to know how to gear a list with the information contained within the save.
PlayerData class:
using UnityEngine;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
[Serializable]
public class PlayerData {
public string highscore;
public string playername;
public string typeScore;
}