Created
July 8, 2018 01:46
-
-
Save clintonmedbery/ac51e7dcdb13122d3cba2a094bc668e7 to your computer and use it in GitHub Desktop.
Save Data Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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