Skip to content
Snippets Groups Projects
Commit 40c68b68 authored by zohaib's avatar zohaib
Browse files

Saving and loading functions are done

parent d58a7af6
No related branches found
No related tags found
No related merge requests found
......@@ -58,24 +58,40 @@ public class CityGen : MonoBehaviour {
}
void save(){
}
void load(){
}
}
public City city;
private string jsonFilePath = "/CityData/data.json";
// Use this for initialization
void Start () {
save();
load();
}
// Update is called once per frame
void Update () {
}
// Save the data about city.
void save (string fileName = "data") {
// Covert city ovject to json.
string cityDataAsJson = JsonUtility.ToJson(this.city);
//print(Application.persistentDataPath + this.jsonFilePath);
// Creates a directory in local disk.
System.IO.Directory.CreateDirectory(Application.persistentDataPath + "/CityData");
// Write all the data to a file.
System.IO.File.WriteAllText(Application.persistentDataPath + this.jsonFilePath, cityDataAsJson);
}
// Load the data about city.
void load(){
string cityDataAsJson = System.IO.File.ReadAllText(Application.persistentDataPath + this.jsonFilePath);
city = JsonUtility.FromJson<City>(cityDataAsJson);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment