1
Hello I am creating a "save" system for games and would like to know how I can generate a list from an object BinaryFormatter
? this file is formed from 3 information, and would like to generate a list with these values, follows the codes:
Create the archive:
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 carry 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);
}
wanted to know how to list the information contained within 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;
}
Have you tried using?
using System.Collections.Generic;
public static List<Game> savedGames = new List<Game>();
By the way, you want to create a list with multiple birds, or you want to put the save data inside a list?– Nils
is a scoreboard save, I want to put the save data inside the list.
– Hebert Lima
Are your save and load working as you expected? If yes, then now just take the values you received in the load and assign to a list.
public static List<Placar> resultados
andresultados.add(Placar valor)
– Nils
yes it is working normally, I can recover only the last values I have tried, however it is not possible to convert an object of type
PlayerData
for aList<PlayerData>
directly, I needed to list the internal save items withHasTable
to then pass them to the list and from what I understood this occurs because my Save does not have an indexing formatting, it is not a list;– Hebert Lima