/// Save data to Json File /// /// @param fileName /// the file name /// @param saveData /// Data to save /// @param onOverwriteDelegate /// Function that is called if file already exists /// public static void SaveDataToJsonFile <T>(string fileName, T saveData, FileSystem.Location location = FileSystem.Location.Persistent, System.Func <string, bool> onOverwriteDelegate = null) { #if UNITY_WEBGL return; #endif string data = JsonWrapper.Serialize(saveData); if (FileSystem.DoesDirectoryExist(fileName, location)) { if ((onOverwriteDelegate == null) || (onOverwriteDelegate(fileName) == true)) { FileSystem.WriteTextFile(data, fileName, location); } } else { FileSystem.WriteTextFile(data, fileName, location); } #if UNITY_EDITOR //Only do refresh if were on the main thread if (GlobalDirector.Service <TaskSchedulerService>().IsMainThread()) { UnityEditor.AssetDatabase.Refresh(); } #endif }
/// @param path /// The path of the file to parse /// /// @return The parsed dictionary /// public static Dictionary <string, object> ParseJsonFile(string path, FileSystem.Location location = FileSystem.Location.Persistent) { #if UNITY_WEBPLAYER == false if (FileSystem.DoesFileExist(path, location)) { // If failing switch Player to Android / iOS string json = FileSystem.ReadTextFile(path, location); return(Deserialize(json) as Dictionary <string, object>); } #endif return(null); }