Ejemplo n.º 1
0
    public static void SetGridMap(Map _map)
    {
        Vector2Int mapSize = _map.mapSize;

        Point[,] gridMap = GridGenerator.CreateEmptyGrid(mapSize);

        GameObject[] tiles = GameObject.FindGameObjectsWithTag("Tile");

        for (int i = 0; i < tiles.Length; i++)
        {
            var tilePos = tiles[i].transform.position;
            if (tilePos.x >= 0 && tilePos.z >= 0 && tilePos.x <= mapSize.x * WorldManager.gridSize && tilePos.z <= mapSize.y * WorldManager.gridSize)
            {
                var gridPos   = new Vector2Int(Mathf.RoundToInt(tilePos.x / WorldManager.gridSize), Mathf.RoundToInt(tilePos.z / WorldManager.gridSize));
                var gridPoint = gridMap[gridPos.x, gridPos.y];
                gridPoint.pointTile   = tiles[i];
                gridPoint.buildHeight = tiles[i].transform.position.y;
                gridPoint.buildable   = true;
            }
        }
        GridGenerator.AddNatureLayer(gridMap);

        _map.SetGrid(gridMap);
    }