Esempio n. 1
0
    private bool HoverTile(RaycastHit tileHit)
    {
        ITile hoverNow =
            (
                (tileHit.collider != null) ?
                tileHit.collider.gameObject.GetComponent <ITile>() :
                null
            );

        int dir = GetTileDirection(tileHit);

        if (selectedUnit != null && hoverNow != null && selectedUnit.IsTilePassable(hoverNow))
        {
            if (!selectedUnit.GetTerrainWalkability(hoverNow.Terrain).Passable)
            {
                return(false);
            }

            if (!hoverNow.Equals(hoverOver) || hoverDirection != dir) // Calculates shortest path and shows it.
            {
                hoverDirection = dir;
                hoverOver      = hoverNow;
                IEnumerable <IPathNode <HexNode> > path = hexControl.GetShortestPath(selectedUnit, selectedUnit.Tile, hoverNow, hoverDirection);
                ClearGameObjectList(highlightedPath);
                HighlightPath(path);

                int pathCount = highlightedPath.Count;
                if (pathCount > 0)
                {
                    if (dir == 6)
                    {
                        highlightedPath[pathCount - 1].transform.rotation = lastPathArrowRotation;
                    }
                    else
                    {
                        highlightedPath[pathCount - 1].transform.rotation =
                            Quaternion.Euler(90, HexUtil.DirectionRotation((HexDirection)dir) - 90, 0);
                    }
                }
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }