void loadMapFromXML(string mapName) { MapXMLContainer container = MapSaveLoad.Load(mapName); mapSize = container.size; for (int i = 0; i < mapTransform.childCount; i++) { Destroy(mapTransform.GetChild(i).gameObject); } for (int i = 0; i < mapSize; i++) { List <Tile> row = new List <Tile>(); for (int j = 0; j < mapSize; j++) { Tile tile = Instantiate(PrefabHolder.instance.TILE_BASE_PREFAB, new Vector3(i - Mathf.Floor(mapSize / 2), 0, -j + Mathf.Floor(mapSize / 2)), Quaternion.Euler(new Vector3())).GetComponent <Tile>(); tile.transform.parent = mapTransform; tile.gridPosition = new Vector2(i, j); tile.setType((TileType)container.tiles.Where(x => x.locX == i && x.locY == j).First().id); row.Add(tile); } map.Add(row); } }
public static MapXMLContainer Load(string filename) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(filename, FileMode.Open); MapXMLContainer save = bf.Deserialize(stream) as MapXMLContainer; stream.Close(); return(save); }
public static void Save(MapXMLContainer mapContainer, string filename) { MapXMLContainer save = mapContainer; BinaryFormatter bf = new BinaryFormatter(); var serializer = new XmlSerializer(typeof(MapXMLContainer)); FileStream stream = File.Create(filename); bf.Serialize(stream, save); stream.Close(); }