]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Saving/SaveSystem.cs
SaveSystem v0.1 NICHT FUNKTIONAL!!!
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Saving / SaveSystem.cs
1 using UnityEngine;
2 using System.IO;
3 using System.Runtime.Serialization.Formatters.Binary;
4
5 public static class SaveSystem
6 {
7     public static void SavePlayer (CheckpointManager cm, Cheese cheese)
8     {
9         BinaryFormatter formatter = new BinaryFormatter();
10         string path = Application.persistentDataPath + "/data.lol";
11         FileStream stream = new FileStream(path, FileMode.Create);
12
13         PlayerData data = new PlayerData(cm, cheese);
14
15         formatter.Serialize(stream, data);
16         stream.Close();
17     }
18
19     public static PlayerData LoadPlayer ()
20     {
21         string path = Application.persistentDataPath + "/data.lol";
22         if (File.Exists(path))
23         {
24             BinaryFormatter formatter = new BinaryFormatter();
25             FileStream stream = new FileStream(path, FileMode.Open);
26
27             formatter.Deserialize(stream);
28
29             PlayerData data = formatter.Deserialize(stream) as PlayerData;
30             stream.Close();
31
32             return data;
33         }
34         else
35         {
36             Debug.LogError("Save file not found in" + path);
37             return null;
38         }
39     }
40 }