public static WorldProgressSave GetSavedFromFiles(string dir, string name) { BinaryFormatter bf = new BinaryFormatter(); FileStream strm = File.Open(Path.Combine(dir, name + fileType), FileMode.Open); WorldProgressSave savedGame = (WorldProgressSave)bf.Deserialize(strm); strm.Close(); return(savedGame); }
public static WorldProgressSave GetSavedGameFromResources(string dir, string name) { TextAsset file = Resources.Load <TextAsset>(dir + "/" + name); MemoryStream str = new MemoryStream(file.bytes); BinaryFormatter bf = new BinaryFormatter(); WorldProgressSave savedGame = (WorldProgressSave)bf.Deserialize(str); str.Close(); return(savedGame); }
public static void SaveScenario(GameObject go, string filename) { if (!Directory.Exists(scenariosDirectory)) { Directory.CreateDirectory(scenariosDirectory); } //BasicWorldSave savedGame = new BasicWorldSave(go); WorldProgressSave savedGame = new WorldProgressSave(go); BinaryFormatter bf = new BinaryFormatter(); FileStream strm = File.Create(Path.Combine(scenariosDirectory, filename + ".bytes")); bf.Serialize(strm, savedGame); strm.Close(); Debug.Log(filename + " saved!"); }
public static void SaveGame(GameObject go, string dir, string filename) { string datapath = Application.persistentDataPath + "/"; if (!Directory.Exists(datapath + dir)) { Directory.CreateDirectory(datapath + dir); } WorldProgressSave savedGame = new WorldProgressSave(go); BinaryFormatter bf = new BinaryFormatter(); FileStream strm = File.Create(Path.Combine(datapath + dir, filename + fileType)); bf.Serialize(strm, savedGame); strm.Close(); Debug.Log(filename + " saved!"); }
public void LoadSavedGame(WorldProgressSave w) { Map = w.world; timeController.Load(w.time); population.Load(w.population); money.Load(w.money); cameraController.Load(w.camera); actionSelecter.Load(w.actionSelecter); immigration.Load(w.immigration); trade.Load(w.trade); diplomacy.Load(w.diplomacy); scenario.Load(w.scenario); research.Load(w.research); ProductivityController.LoadProductivities(w.productivities, w.automation); notifications.LoadEvents(w.Events); //load whitelist for items ResourcesDatabase.LoadWhitelist(w.Whitelist); //GO THROUGH LISTS OF OBJECTS AND ACTIVATE THEM USING THE LOADMAPOBJECT() FUNCTION //structures foreach (ObjSave save in w.structures) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.jobcentres) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.workplaces) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.storagebuildings) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.generators) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.stables) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.houses) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.wtps) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.canals) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.crops) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.farmhouses) { LoadMapObject(save).transform.parent = structures.transform; } //walkers foreach (ObjSave save in w.animals) { LoadMapObject(save).transform.parent = walkers.transform; } foreach (ObjSave save in w.walkers) { LoadMapObject(save).transform.parent = walkers.transform; } }
public void LoadSavedGame(WorldProgressSave w) { Map = w.world; timeController.Load(w.time); labor.Load(w.labor); money.Load(w.money); cameraController.Load(w.camera); actionSelecter.Load(w.actionSelecter); immigration.Load(w.immigration); trade.Load(w.trade); diplomacy.Load(w.diplomacy); scenario.Load(w.scenario); //GO THROUGH LISTS OF OBJECTS AND ACTIVATE THEM USING THE LOADMAPOBJECT() FUNCTION //structures foreach (ObjSave save in w.structures) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.workplaces) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.storagebuildings) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.generators) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.factories) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.stables) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.houses) { LoadMapObject(save).transform.parent = structures.transform; } foreach (ObjSave save in w.markets) { LoadMapObject(save).transform.parent = structures.transform; } //walkers foreach (ObjSave save in w.animals) { LoadMapObject(save).transform.parent = walkers.transform; } foreach (ObjSave save in w.walkers) { LoadMapObject(save).transform.parent = walkers.transform; } foreach (ObjSave save in w.venders) { LoadMapObject(save).transform.parent = walkers.transform; } }