public void Carregar() { if (File.Exists(Application.persistentDataPath + "/playerInfo.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open); //Usa a função bf.Deserialize para pegar os dados de volta e usa um cast antes do bf para o formato do objeto ConfigJogo data = (ConfigJogo)bf.Deserialize(file); file.Close(); this.Fase = data.Fase; this.Estilo = data.Estilo; this.Rock = data.Rock; this.Funk = data.Funk; this.Reggae = data.Reggae; this.Eletronica = data.Eletronica; this.Alcool = data.Alcool; this.Cigarro = data.Cigarro; this.Maconha = data.Maconha; this.Cocaina = data.Cocaina; this.Inalantes = data.Inalantes; this.Alucinogeno = data.Alucinogeno; this.Ecstasy = data.Ecstasy; this.Crack = data.Crack; } }
public void Salvar() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat"); //Preenche um objeto serializado que é só criar um classe para armazenar os valores e declarar [Serializable] antes dela ConfigJogo data = new ConfigJogo(); data.Fase = this.Fase; data.Estilo = this.Estilo; data.Rock = this.Rock; data.Funk = this.Funk; data.Reggae = this.Reggae; data.Eletronica = this.Eletronica; data.Alcool = this.Alcool; data.Cigarro = this.Cigarro; data.Maconha = this.Maconha; data.Cocaina = this.Cocaina; data.Inalantes = this.Inalantes; data.Alucinogeno = this.Alucinogeno; data.Ecstasy = this.Ecstasy; data.Crack = this.Crack; //usa o BinaryFormatter para gravar os dados no arquivo bf.Serialize(file, data); file.Close(); }