Skip to content

Instantly share code, notes, and snippets.

@clintonmedbery
Created July 8, 2018 01:46
Show Gist options
  • Save clintonmedbery/ac51e7dcdb13122d3cba2a094bc668e7 to your computer and use it in GitHub Desktop.
Save clintonmedbery/ac51e7dcdb13122d3cba2a094bc668e7 to your computer and use it in GitHub Desktop.
Save Data Unity
public void SaveTransactions(){
FileStream file = File.Create(Application.persistentDataPath + "/needItData.dat");
TransactionData transactionData = new TransactionData(amount, transactions);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(file, transactionData);
file.Close();
}
public void LoadTransactions(){
if (File.Exists(Application.persistentDataPath + "/needItData.dat"))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/needItData.dat", FileMode.Open);
TransactionData data = binaryFormatter.Deserialize(file) as TransactionData;
file.Close();
transactions = data.transactions;
amount = data.amount;
transactions = data.transactions;
}
}
[Serializable]
class TransactionData
{
public double amount;
public List<Transaction> transactions = new List<Transaction>();
public TransactionData(double amount, List<Transaction> transactions){
this.amount = amount;
this.transactions = transactions;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment