// ------------------- FUNCOES ------------------- // // Salva o arquivo public void SaveData() { string path = string.Concat(Application.persistentDataPath, "/savegame.dat"); // Cria arquivo e dados using (FileStream fileStream = File.Create(path)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); // Passa dados para classe DadosJogadorExemploRevisao dadosJogadorExemploRevisao = new DadosJogadorExemploRevisao(); dadosJogadorExemploRevisao.PlayerID = this.playerID; dadosJogadorExemploRevisao.PlayerName = this.playerName; dadosJogadorExemploRevisao.Score = this.score; dadosJogadorExemploRevisao.Letters = this.letters; // Serializa dados e fecha o arquivo binaryFormatter.Serialize(fileStream, dadosJogadorExemploRevisao); } }
// Carrega o arquivo public void LoadData() { string path = string.Concat(Application.persistentDataPath, "/savegame.dat"); // Verifica se arquivo existe if (File.Exists(path)) { // Carrega arquivo using (FileStream fileStream = File.Open(path, FileMode.Open)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); // Carrega dados DadosJogadorExemploRevisao dadosJogadorExemploRevisao = (DadosJogadorExemploRevisao)binaryFormatter.Deserialize(fileStream); this.playerID = dadosJogadorExemploRevisao.PlayerID; this.playerName = dadosJogadorExemploRevisao.PlayerName; this.score = dadosJogadorExemploRevisao.Score; this.letters = dadosJogadorExemploRevisao.Letters; } } }