Example #1
0
    public bool IsTileValidNeighbor(GridTileData other)
    {
        bool result = false;

        //are the tiles sharing the same tileasset
        if (other.Tile == Tile)
        {
            //is the other tile not this tile
            if (other.GridPosition != GridPosition)
            {
                //is the other left or right of this tile
                if (other.GridPosition.y <= GridPosition.y + 1 && other.GridPosition.y >= GridPosition.y - 1)
                {
                    //due to the nature of the hexagongrid the coordinates may only change on the y-coordinates depending on the positioning of the origin-tile
                    //(on even y-positions the top-left and top-right and on odd y-positions the bottom-left and bottom-right)
                    if ((GridPosition.y % 2 == 0 && other.GridPosition.x > GridPosition.x) ||
                        (GridPosition.y % 2 != 0 && other.GridPosition.x < GridPosition.x))
                    {
                        if (other.GridPosition.y == GridPosition.y)
                        {
                            result = true;
                        }
                    }
                    else if (other.GridPosition.x <= GridPosition.x + 1 && other.GridPosition.x >= GridPosition.x - 1)
                    {
                        result = true;
                    }
                }
            }
        }

        return(result);
    }
Example #2
0
 public void SetTileData(GridTileData tileData)
 {
     if (m_tileData != tileData)
     {
         m_tileData    = tileData;
         m_icon.sprite = m_tileData.IconImage;
     }
 }
Example #3
0
    public void SetTileData(GridTileData tileData)
    {
        m_tileData = tileData;
        m_bulletScroll.SetBulletsCount(m_tileData.m_datas.Length);

        m_selectedDataIndex = -1;
        RefreshContent(0);
    }
Example #4
0
    public GridTileData GetTileDataFromPosition(Vector3 mouseWorldPosition)
    {
        Vector3Int tileCoordinate = grid.WorldToCell(mouseWorldPosition);
        Tile       selectedTile   = map.GetTile <Tile>(tileCoordinate);

        GridTileData tileData = null;

        if (selectedTile != null)
        {
            tileData = new GridTileData(tileCoordinate, selectedTile);
        }

        return(tileData);
    }
Example #5
0
    private void SelectTiles()
    {
        Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        GridTileData selectedTileData = GridController.GetTileDataFromPosition(mouseWorldPos);

        if (selectedTileData != null)
        {
            if (currentTiles.Count == 0)
            {
                currentTiles.Add(selectedTileData);

                Highlight.SetHighlight(selectedTileData.GridPosition);
            }
            else
            {
                var lastTileData = currentTiles[currentTiles.Count - 1];
                if (!currentTiles.Contains(selectedTileData))
                {
                    if (lastTileData.IsTileValidNeighbor(selectedTileData))
                    {
                        currentTiles.Add(selectedTileData);
                        Highlight.SetHighlight(selectedTileData.GridPosition);
                    }
                }
                else
                {
                    if (lastTileData != selectedTileData)
                    {
                        if (selectedTileData == currentTiles[currentTiles.Count - 2])
                        {
                            Highlight.RemoveHighlight(lastTileData.GridPosition);
                            currentTiles.Remove(lastTileData);
                        }
                    }
                }
            }
        }
    }