Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- public class SaveManager : MonoBehaviour {
- //when is this called, onquite
- public static void SaveCurrency(CurrencyManager currencyManager)
- {
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- FileStream fileStream = new FileStream(Application.persistentDataPath + "/player.dat", FileMode.Create);
- PlayerData playerData = new PlayerData();
- binaryFormatter.Serialize(fileStream, playerData);
- fileStream.Close();
- }
- /*
- public static int LoadCurrency()
- {
- if (File.Exists(Application.persistentDataPath + "/player.dat"))
- {
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- FileStream fileStream = new FileStream(Application.persistentDataPath + "/player.dat", FileMode.Open);
- PlayerData playerData = binaryFormatter.Deserialize(fileStream) as PlayerData;
- fileStream.Close();
- return playerData.currency;
- }
- else
- {
- Debug.LogError("File doesn't exist.");
- return new int();
- }
- }
- */
- public static PlayerData LoadData()
- {
- if (File.Exists(Application.persistentDataPath + "/player.dat"))
- {
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- FileStream fileStream = new FileStream(Application.persistentDataPath + "/player.dat", FileMode.Open);
- PlayerData playerData = binaryFormatter.Deserialize(fileStream) as PlayerData;
- fileStream.Close();
- return playerData;
- }
- else
- {
- Debug.LogError("File doesn't exist.");
- return new PlayerData();
- }
- }
- public static void SaveData()
- {
- //this is god's light, yw
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- FileStream fStream = new FileStream(Application.persistentDataPath + "/player.dat", FileMode.Create);
- PlayerData pData = new PlayerData();
- binaryFormatter.Serialize(fStream, pData);
- fStream.Close();
- }
- [System.Serializable]
- // this is helpful, allows us an abstract view of what the player has - need to use this
- // to our advantage
- public class PlayerData
- {
- public int currency;
- public int hullLvl;
- //let me try sth to see what it saves
- public PlayerData()
- {
- //dont stress too much over it now, just try to get the logic
- hullLvl = UpgradeManager.hullLvlIndex;
- currency = CurrencyManager.Currency;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement