[MenuItem("Developers/Load")]
public static void Load()
{
LoadFromFile("UserProfileData");
LoadFromFile("ShopSave");
LoadFromFile("ChallengeSave");
LoadFromFile("DailyRewardSave");
LoadFromFile("CitySaveData");
LoadFromFile("DailyWeeklyTaskSave");
LoadFromFile("RacingProgressData");
UnityLog.LogC("Load Data: Done");
}
#endif
public static void SaveToFile(string id)
{
var identifier = id;
var filePath = string.Format ( "{0}/{1}", Application.persistentDataPath, identifier );
// var content = PlayerPrefs.GetString(filePath);
if (Directory.Exists(filePath) && File.Exists ( filePath ))
{
var content = File.ReadAllText ( filePath, Encoding.UTF8 );
WriteToFile(Application.streamingAssetsPath + "/" + id, content);
}
}
public static void LoadFromFile(string id)
{
var identifier = id;
var content = ReadFromFile(Application.streamingAssetsPath + "/" + id);
//PlayerPrefs.SetString(filePath, content);
var filePath = string.Format ( "{0}/{1}", Application.persistentDataPath, identifier );
File.WriteAllText ( filePath, content);
}
public static void WriteToFile(string filePath, string content)
{
using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
using (StreamWriter streamWriter = new StreamWriter(fileStream))
{
streamWriter.WriteLine(content);
}
}
}
public static string ReadFromFile(string filePath)
{
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
using (StreamReader streamReader = new StreamReader(fileStream, System.Text.Encoding.ASCII))
{
string content = streamReader.ReadToEnd();
return content;
}
}
}