public void InitializeDatabase() { if (!File.Exists(filePath)) { Directory.CreateDirectory(directoryPath); } using (var connection = new LiteDatabase(filePath)) { var houses = connection.GetCollection <House>(); //var expenses = connection.GetCollection<House>(); int result = houses.Count(); if (result == 0) { string r = System.Reflection.Assembly.GetExecutingAssembly().Location; int index = r.LastIndexOf("\\"); var dir = $"{r.Substring(0, index)}\\"; var file = $"{dir}\\RedmondHouses.xml"; using (StreamReader reader = new StreamReader(file)) { XmlSerializer serializer = new XmlSerializer(typeof(AllHouses)); AllHouses school = (AllHouses)serializer.Deserialize(reader); foreach (var item in school.Houses.Take(10)) { item.Schools.Add(new School { Name = "Seatle High school", Type = "Publich high school", Size = 2941 }); item.Schools.Add(new School { Name = "Seatle Academy of Arts", Type = "Pricate middle school", Size = 948 }); item.Schools.Add(new School { Name = "Pike Place Primary School", Type = "Publich primary school", Size = 492 }); houses.Insert(item); } } } } }
IEnumerator FindHouses() { request = UnityWebRequest.Get(house_url); //grab all houses yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { print("Error downloading: " + request.error); } else { Debug.Log("POST complete!"); Debug.Log(request.downloadHandler.text); } houses = JsonUtility.FromJson <AllHouses>(request.downloadHandler.text); //easiest solution, even though the very simple class looks dumb yield return(StartCoroutine(HouseInfo())); }