예제 #1
0
        private HexDirection GetSextantOfMouse(IHexCell cell)
        {
            var mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

            if (Physics.Raycast(mouseRay, out hit) && Grid.HasCellAtLocation(hit.point))
            {
                return(GetNearestEdgeOfCellFromPoint(cell, hit.point));
            }
            else
            {
                Debug.LogWarning("Raycast did not hit terrain");
                return(HexDirection.NE);
            }
        }
예제 #2
0
        public IHexCell GetCellAtPoint(Vector3 point)
        {
            if (!Grid.HasCellAtLocation(point))
            {
                return(null);
            }

            var gridCell = Grid.GetCellAtLocation(point);

            foreach (var direction in EnumUtil.GetValues <HexDirection>())
            {
                if (CellContourCanon.IsPointWithinContour(point.ToXZ(), gridCell, direction))
                {
                    return(gridCell);
                }
            }

            foreach (var neighbor in Grid.GetNeighbors(gridCell))
            {
                foreach (var direction in EnumUtil.GetValues <HexDirection>())
                {
                    if (CellContourCanon.IsPointWithinContour(point.ToXZ(), neighbor, direction.Opposite()))
                    {
                        return(neighbor);
                    }
                }
            }

            return(null);
        }