diff --git a/Assets/Scripts/Managers/DataManager.cs b/Assets/Scripts/Managers/DataManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..5e8fa4067826e79f5f33acb630f37d38c3845119 --- /dev/null +++ b/Assets/Scripts/Managers/DataManager.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using System; + +public static class DataManager +{ + + public static void SaveData (string name_, int score_, string GAMEMODE) { + string path; + + DateTime timestamp = DateTime.Now; + string unixTime = ((DateTimeOffset)timestamp).ToUnixTimeSeconds().ToString(); + + BinaryFormatter formatter = new BinaryFormatter(); + if (GAMEMODE == "ZEN") { + path = Application.persistentDataPath + "/zen/" + unixTime + ".fun"; + } else { + path = Application.persistentDataPath + "/waves/" + unixTime + ".fun"; + } + FileStream stream = new FileStream(path, FileMode.Create); + + PlayerData data = new PlayerData(name_, score_); + + formatter.Serialize(stream, data); + stream.Close(); + } + + public static PlayerData LoadPlayer(string GAMEMODE) { + string path; + + DateTime timestamp = DateTime.Now; + string unixTime = ((DateTimeOffset)timestamp).ToUnixTimeSeconds().ToString(); + + if (GAMEMODE == "ZEN") { + path = Application.persistentDataPath + "/zen/" + unixTime + ".fun"; + } else { + path = Application.persistentDataPath + "/waves/" + unixTime + ".fun"; + } + + 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; + } + } + +} diff --git a/Assets/Scripts/Managers/DataManager.cs.meta b/Assets/Scripts/Managers/DataManager.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..9d4c124b3e01bac99c68188790d907d4b32a2510 --- /dev/null +++ b/Assets/Scripts/Managers/DataManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0180904ffc9319409bfd28e038b69aa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/PlayerData.cs b/Assets/Scripts/Player/PlayerData.cs new file mode 100644 index 0000000000000000000000000000000000000000..9bf21e9aa1039bf9944b02eecc7c765af8c332b7 --- /dev/null +++ b/Assets/Scripts/Player/PlayerData.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[System.Serializable] +public class PlayerData +{ + public string name; + public int score; + + public PlayerData (string name_, int score_) { + name = name_; + score = score_; + } + +} diff --git a/Assets/Scripts/Player/PlayerData.cs.meta b/Assets/Scripts/Player/PlayerData.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..4d79a5e8124a7c35231f3aa236bdcdc92eb20901 --- /dev/null +++ b/Assets/Scripts/Player/PlayerData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e960fb47cb9f6c4eaa647b2ab101317 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: