private void loadMapFromXml()
    {
        CellMapXMLContainer container = MapSaveLoad.Load("map.xml");

        mapSize = container.size;

        //initially remove all children
        for (int i = 0; i < mapTransform.childCount; i++)
        {
            Destroy(mapTransform.GetChild(i).gameObject);
        }

        map = new List <List <Cell> >();
        for (int i = 0; i < mapSize; i++)
        {
            List <Cell> row = new List <Cell>();
            for (int j = 0; j < mapSize; j++)
            {
                Cell tile = ((GameObject)Instantiate(PrefabHolder.instance.BASE_TILE_PREFAB, new Vector3(i - Mathf.Floor(mapSize / 2), 0, -j + Mathf.Floor(mapSize / 2)), Quaternion.Euler(new Vector3()))).GetComponent <Cell>();
                tile.transform.parent = mapTransform;
                tile.gridPosition     = new Vector2(i, j);
                tile.setType((CellType)container.cells.Where(x => x.locX == i && x.locY == j).First().id);
                row.Add(tile);
            }
            map.Add(row);
        }
    }
    private void CreateMap()
    {
        CellMapXMLContainer container = MapSaveLoad.Load("map.xml");

        mapSize = container.size;

        //initially remove all children
        // for (int i = 0; i < mapTransform.childCount; i++)
        //{
        //    Destroy(mapTransform.GetChild(i).gameObject);
        //}

        map = new List <List <Cell> >();
        for (int i = 0; i < mapSize; i++)
        {
            List <Cell> row = new List <Cell>();
            for (int j = 0; j < mapSize; j++)
            {
                GameObject cellPrefab;
                cellPrefab = ((GameObject)Instantiate(PrefabHolder.instance.BASE_TILE_PREFAB.gameObject, new Vector3(i - Mathf.Floor(mapSize / 2), 0, -j + Mathf.Floor(mapSize / 2)), Quaternion.Euler(new Vector3())));
                Cell cell = cellPrefab.GetComponent <Cell>();
                cell.transform.parent = mapTransform;
                cell.gridPosition     = new Vector2(i, j);
                cell.type             = (CellType)(container.cells.Where(x => x.locX == i && x.locY == j).First().id);
                row.Add(cell);
            }
            map.Add(row);
        }
    }
 public static void Save(CellMapXMLContainer mapContainer, string filename)
 {
     var serializer = new XmlSerializer(typeof(CellMapXMLContainer));
     using (var stream = new FileStream(filename, FileMode.Create))
     {
         serializer.Serialize(stream, mapContainer);
     }
 }