private void LoadRoster() { string path = Path.Combine(Application.streamingAssetsPath, "PeopleData.json"); string debug = Path.Combine(Application.streamingAssetsPath, "debug.json"); if (!File.Exists(path)) { Debug.Log("NO SAVE FILE RECOGNISED"); } else { PeopleDataObject allPeople = PeopleDataObject.Instance; string jsonString = File.ReadAllText(path); //check that the file is read correctly File.WriteAllText(debug, jsonString); allPeople = JsonConvert.DeserializeObject <PeopleDataObject>(jsonString, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); People = allPeople.People; Person.AllTimeCount = allPeople.Count; foreach (Person person in People) { person.Notification("loaded from save."); } Debug.Log("Loaded"); } }
private void SaveRoster() { PeopleDataObject allPeople = PeopleDataObject.Instance; allPeople.People = People; allPeople.Count = Person.AllTimeCount; //serialise list of people, indented, with type info var jsonString = JsonConvert.SerializeObject(allPeople, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); string path = Path.Combine(Application.streamingAssetsPath, "PeopleData.json"); if (!File.Exists(path)) { File.Create(path).Dispose(); } File.WriteAllText(path, jsonString); Debug.Log("Saved"); }