using System.IO; using UnityEngine; namespace Core.Data { /// /// Json implementation of file saver /// public class JsonSaver : FileSaver where T : IDataStore { public JsonSaver(string filename) : base(filename) { } /// /// Save the specified data store /// public override void Save(T data) { string json = JsonUtility.ToJson(data); using (StreamWriter writer = GetWriteStream()) { writer.Write(json); } } /// /// Load the specified data store /// public override bool Load(out T data) { if (!File.Exists(m_Filename)) { data = default(T); return false; } using (StreamReader reader = GetReadStream()) { data = JsonUtility.FromJson(reader.ReadToEnd()); } return true; } } }