Beispiel #1
0
    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);
        }
    }
    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);
        }
    }
 private void Load()
 {
     if (flowData != null)
     {
         Debug.Log("load");
         mapSaveLoad.Load(flowData);
     }
 }