mirror of
https://github.com/Kizuren/ShantiManti.git
synced 2025-12-21 21:16:04 +01:00
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using UnityEngine;
|
|
using System.IO;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
|
|
public static class SaveSystem
|
|
{
|
|
public static void SavePlayer()
|
|
{
|
|
BinaryFormatter formatter = new BinaryFormatter();
|
|
string path = Application.persistentDataPath + "/player.save";
|
|
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.save";
|
|
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;
|
|
}
|
|
|
|
Debug.LogError("SaveFile not found in " + path);
|
|
Debug.Log("Creating new save file...");
|
|
SavePlayer();
|
|
return LoadPlayer();
|
|
}
|
|
|
|
}
|