init
This commit is contained in:
commit
341a877b4a
2338 changed files with 1346408 additions and 0 deletions
34
Assets/Scripts/SaveSystem.cs
Normal file
34
Assets/Scripts/SaveSystem.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
public static class SaveSystem{
|
||||
|
||||
public static void SavePlayer(PlayerController player){
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
|
||||
string path = Application.persistentDataPath + "/gaviota.man";
|
||||
FileStream stream = new FileStream(path, FileMode.Create);
|
||||
|
||||
PlayerData data = new PlayerData(player);
|
||||
|
||||
formatter.Serialize(stream, data);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
public static PlayerData LoadPlayer(){
|
||||
string path = Application.persistentDataPath + "/gaviota.man";
|
||||
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 file not found in " + path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue