/// 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 }
public void ShouldSerializeObject() { IJsonInterpreter wrapper = new JsonWrapper(); EmptyAttributeSet attributeSet = new EmptyAttributeSet(); string expectedJson = "{\"characterAttributes\":[{\"characterAttribute\":\"STR\",\"value\":0},{\"characterAttribute\":\"DEX\",\"value\":0},{\"characterAttribute\":\"CON\",\"value\":0},{\"characterAttribute\":\"INT\",\"value\":0},{\"characterAttribute\":\"WIS\",\"value\":0},{\"characterAttribute\":\"CHR\",\"value\":0},]}"; string actualJson = wrapper.Serialize(attributeSet); actualJson.Should().Be("{}"); }