public void Save() { cachedObj.ToList().ForEach(pair => { var json = JsonUtilityEx.ToJson(pair.Value); jsonDic[pair.Key] = json; }); var list = jsonDic.Select(pair => new KeyValue() { key = pair.Key, value = pair.Value }).ToList(); var str = JsonUtilityEx.ToJson(new ListWrapper() { list = list }, true); var p = path; var dir = Path.GetDirectoryName(p); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } File.WriteAllText(p, str); }
public void OnExport(object sender) { var filename = UnityEditor.EditorUtility.SaveFilePanel("Save exported data", System.IO.Path.GetDirectoryName(Application.dataPath), "config", "txt"); if (filename.HasContent(4)) { System.IO.File.WriteAllText(filename, JsonUtilityEx.ToJson(data), System.Text.Encoding.UTF8); } }
void TestConsistency <T>(T v, IEqualityComparer <T> comparer = null) { var json = JsonUtilityEx.ToJson(v); var newV = JsonUtilityEx.FromJson <T>(json); if (comparer != null) { Assert.AreEqual(v, newV, $"{typeof(T).Name} NOT Consistency", comparer); } else { Assert.AreEqual(v, newV, $"{typeof(T).Name} NOT Consistency"); } }