-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveSystem.cs
35 lines (32 loc) · 1.04 KB
/
SaveSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.IO;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
public static class SaveSystem
{
public static void SavePlayer()
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/Player.Stuart";
FileStream stream = new FileStream(path, FileMode.Create);
PlayerData data = new PlayerData();
formatter.Serialize(stream, data);
stream.Close();
}
public static PlayerData LoadPlayer()
{
string path = Application.persistentDataPath + "/Player.Stuart";
if(File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
PlayerData data = formatter.Deserialize(stream) as PlayerData;
stream.Close();
return data;
}
else
{
Debug.LogError("Save Not Found" + path);
return null;
}
}
}