Exemplo n.º 1
0
    private List <TransportNetworkTile> GetNeighbors(TransportNetworkTile tile)
    {
        List <TransportNetworkTile> neighbors      = new List <TransportNetworkTile>();
        TransportNetworkTile        neighborTop    = GetNeighborTop(tile);
        TransportNetworkTile        neighborBottom = GetNeighborBottom(tile);
        TransportNetworkTile        neighborLeft   = GetNeighborLeft(tile);
        TransportNetworkTile        neighborRight  = GetNeighborRight(tile);

        if (neighborTop != null)
        {
            neighbors.Add(neighborTop);
        }
        if (neighborBottom != null)
        {
            neighbors.Add(neighborBottom);
        }
        if (neighborLeft != null)
        {
            neighbors.Add(neighborLeft);
        }
        if (neighborRight != null)
        {
            neighbors.Add(neighborRight);
        }
        return(neighbors);
    }
Exemplo n.º 2
0
 private TransportNetworkTile GetNeighborBottom(TransportNetworkTile tile)
 {
     if (TileIsAtBottomEdge(tile))
     {
         return(null);
     }
     return(tiles[tile.position.x, tile.position.y - 1]);
 }
Exemplo n.º 3
0
 private TransportNetworkTile GetNeighborTop(TransportNetworkTile tile)
 {
     if (TileIsAtTopEdge(tile))
     {
         return(null);
     }
     return(tiles[tile.position.x, tile.position.y + 1]);
 }
Exemplo n.º 4
0
 private TransportNetworkTile GetNeighborRight(TransportNetworkTile tile)
 {
     if (TileIsAtRightEdge(tile))
     {
         return(null);
     }
     return(tiles[tile.position.x + 1, tile.position.y]);
 }
Exemplo n.º 5
0
    public void ClearTileAt(Vector2Int position)
    {
        TransportNetworkTile tile = tiles[position.x, position.y];

        if (tile.type == TransportNetworkTile.Type.Empty)
        {
            Debug.LogError($"ERROR CLEARING TILE: There is nothing to clear at X: {position.x}, Y: {position.y}. ");
        }
        tile.type = TransportNetworkTile.Type.Empty;
    }
Exemplo n.º 6
0
    public void AddRoadAt(Vector2Int position)
    {
        TransportNetworkTile tile = tiles[position.x, position.y];

        if (tile.type == TransportNetworkTile.Type.Road)
        {
            Debug.LogError($"ERROR ADDING ROAD TILE: There already is a road at X: {position.x}, Y: {position.y}. ");
        }
        tile.type = TransportNetworkTile.Type.Road;
    }
Exemplo n.º 7
0
    private bool TileIsAtRightEdge(TransportNetworkTile tile)
    {
        int positionX = tile.position.x;

        if (positionX > tileMapWidth - 1)
        {
            Debug.LogError($"ERROR TRANSPORT NETWORK: Tile {tile} is at position.x = {positionX}, " +
                           $"but the tile map only has a width of {tileMapWidth}. ");
        }
        return(positionX >= tileMapWidth - 1);
    }
Exemplo n.º 8
0
    private bool TileIsAtLeftEdge(TransportNetworkTile tile)
    {
        int positionX = tile.position.x;

        if (positionX < 0)
        {
            Debug.LogError($"ERROR TRANSPORT NETWORK: Tile {tile} is at position.x = {positionX}, " +
                           $"that is outside of the tile map. ");
        }
        return(positionX <= 0);
    }
Exemplo n.º 9
0
 private void Awake()
 {
     tiles = new TransportNetworkTile[tileMapWidth, tileMapHeight];
     for (int i = 0; i < tileMapWidth; i++)
     {
         for (int j = 0; j < tileMapHeight; j++)
         {
             tiles[i, j] = new TransportNetworkTile(i, j);
         }
     }
 }
Exemplo n.º 10
0
    private bool TileIsAtBottomEdge(TransportNetworkTile tile)
    {
        int positionY = tile.position.y;

        if (positionY < 0)
        {
            Debug.LogError($"ERROR TRANSPORT NETWORK: Tile {tile} is at position.y = {positionY}, " +
                           $"that is outside of the tile map. ");
        }
        return(positionY <= 0);
    }
Exemplo n.º 11
0
    private bool TileIsAtTopEdge(TransportNetworkTile tile)
    {
        int positionY = tile.position.y;

        if (positionY > tileMapHeight - 1)
        {
            Debug.LogError($"ERROR TRANSPORT NETWORK: Tile {tile} is at position.y = {positionY}, " +
                           $"but the tile map only has a height of {tileMapHeight}. ");
        }
        return(positionY >= tileMapHeight - 1);
    }