예제 #1
0
    static Tile GetDirectionCube(Tile tile, Hex.CubeDirections dir)
    {
        Hex.OffsetPairs offsetPairs = Hex.GetNeighborFromDir(GridManager.hex, dir, new Hex.OffsetPairs(tile.position.x, tile.position.y));

        if ((offsetPairs.row == tile.position.x && offsetPairs.col == tile.position.y) || offsetPairs.col == -1 || offsetPairs.row == -1)
        {
            return(null);
        }

        offsetPairs.row = Mathf.Clamp(offsetPairs.row, 0, GridManager.grid.GetLength(0) - 1);
        offsetPairs.col = Mathf.Clamp(offsetPairs.col, 0, GridManager.grid.GetLength(1) - 1);

        return(GridManager.grid[offsetPairs.row, offsetPairs.col]);
    }
    /// <summary>
    /// Retrieve tile located in the direction specified from the selected tile.
    /// </summary>
    /// <param name="tile">Target tile.</param>
    /// <param name="dir">Cube direction.</param>
    /// <returns></returns>
    private static Tile GetDirectionCube(Tile tile, Hex.CubeDirections dir)
    {
        Hex.OffsetCoordinates offsetPairs = Hex.GetNeighborFromDir(WorldManager.Hex, dir, new Hex.OffsetCoordinates(tile.Position.x, tile.Position.y));

        if ((offsetPairs.row == tile.Position.x && offsetPairs.col == tile.Position.y) || offsetPairs.col == -1 || offsetPairs.row == -1)
        {
            return(null);
        }

        offsetPairs.row = Mathf.Clamp(offsetPairs.row, 0, WorldManager.World.Tiles.GetLength(0) - 1);
        offsetPairs.col = Mathf.Clamp(offsetPairs.col, 0, WorldManager.World.Tiles.GetLength(1) - 1);

        return(WorldManager.World.Tiles[offsetPairs.row, offsetPairs.col]);
    }