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.Runtime.Serialization.Formatters.Binary;
- using System.IO;
- public class SaveManager : MonoBehaviour
- {
- public static SaveManager instance;
- SaveFile svFile;
- private void Awake()
- {
- if (instance == null)
- instance = this;
- }
- private void OnApplicationQuit()
- {
- ClearTemp();
- }
- public void SetGMData(GameManager mgr)
- {
- svFile.gmDat = new GameData(mgr);
- }
- public void SetPlayerData(Player plyr)
- {
- svFile.plrDat = new PlayerData(plyr);
- }
- public GameData GetGMData()
- {
- if (!svFile.written)
- {
- Debug.Log("Save File had no Game info");
- return null;
- }
- else return svFile.gmDat;
- }
- public PlayerData GetPlayerData()
- {
- if (!svFile.written)
- {
- Debug.Log("Save File had no Player info");
- return null;
- }
- else return svFile.plrDat;
- }
- public void Save(bool level)
- {
- /*
- Debug.Log("Save was called");
- svFile.written = true;
- string folder = Application.dataPath + "/SaveData";
- string path = folder;
- if (level) path += "/Gamestate.temp";
- else path += "/ Save.sav";
- BinaryFormatter bf = new BinaryFormatter();
- if(!Directory.Exists(folder)) Directory.CreateDirectory(folder);
- FileStream file = File.Create(path);
- bf.Serialize(file, svFile);
- file.Close();
- file.Dispose();
- */
- }
- public void Load(bool level)
- {
- /*
- Debug.Log("Tried to load");
- string folder = Application.dataPath + "/SaveData";
- string path = folder;
- if (level) path += "/Gamestate.temp";
- else path += "/Save.sav";
- BinaryFormatter bf = new BinaryFormatter();
- if (File.Exists(path))
- {
- FileStream file = File.Open(path, FileMode.Open);
- SaveFile data = (SaveFile)bf.Deserialize(file);
- file.Close();
- file.Dispose();
- if(data != null)
- svFile = data;
- }
- if (svFile == null)
- {
- svFile = new SaveFile();
- svFile.written = false;
- }
- if (level)
- {
- if (File.Exists(path + ".meta")) File.Delete(path + ".meta");
- File.Delete(path);
- }
- */
- svFile = new SaveFile();
- }
- public void ClearTemp()
- {
- //string path = Application.dataPath + "/SaveData/Gamestate.temp";
- //if (File.Exists(path + ".meta")) File.Delete(path + ".meta");
- //if (File.Exists(path)) File.Delete(path);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement