/*private void OnMouseDown()
     * {
     *  startPositionVector3    = Input.mousePosition;
     *  startPositionVector3Int = Vector3Int.FloorToInt(startPositionVector3);
     * }*/

    /* private void OnMouseUp()
     * {
     *   dropPositionVector3    = Input.mousePosition;
     *   dropPositionVector3Int = Vector3Int.FloorToInt(dropPositionVector3);
     * }*/

    private void OnMouseDrag()
    {
        try
        {
            startPositionVector3   = Input.mousePosition;
            currentPositionVector3 = transform.position;

            var startGridPos = gridMap.WorldToCell(currentPositionVector3);
            var worldPos     = Camera.main.ScreenToWorldPoint(startPositionVector3);
            var gridPos      = gridMap.WorldToCell(worldPos);

            Debug.Log("Current Mouse on Grid " + gridPos);
            Debug.Log("Ghost start Point " + startGridPos);

            var pathAsString = "";

            var path = _pathCalculator.CalculatePath(startGridPos, gridPos);
            foreach (var step in path)
            {
                pathAsString += step.ToString();
            }

            ghost.SetMovementPath(path);

            Debug.Log(ghost.movementPath.ToString());
        }
        catch (Exception ignore)
        {
            // nothing to do
        }
    }
Beispiel #2
0
    /// <summary>
    /// Check if the destination can be reached
    /// </summary>
    /// <param name="_position">destination to reach</param>
    /// <returns>if the destination can be reached</returns>
    public bool CheckDestination(Vector3 _position)
    {
        if (CustomNavMeshManager.Triangles == null || CustomNavMeshManager.Triangles.Count == 0)
        {
            Debug.LogWarning("Triangles Not found. Must build the navmesh for the scene");
            return(false);
        }
        if (isMoving)
        {
            StopAllCoroutines();
        }
        pathState = CalculatingState.Calculating;
        bool _canBeReached = PathCalculator.CalculatePath(OffsetPosition, _position, currentPath, CustomNavMeshManager.Triangles);

        if (_canBeReached)
        {
            pathState = CalculatingState.Ready;
            StopAllCoroutines();
            StartCoroutine(FollowPath());
        }
        else
        {
            pathState = CalculatingState.Waiting;
        }
        return(_canBeReached);
    }
Beispiel #3
0
    private IEnumerator PathRefreshCoroutine()
    {
        while (true)
        {
            // Calculate path for new sets of points and pass it to path segment getter
            pathSegmentGetter.SetPath(pathCalculator.CalculatePath(lastPrintedPoint, GetMouseWorldPosition()));

            // Wait for time dependant on cursor velocity to ensure proper distance between control points.
            yield return(new WaitForSeconds(basePathRefreshTime / velocity));
        }
    }
Beispiel #4
0
        // this method uses the PathCalculator class to calculate the shortest path between 2 points and saves the path into a list
        // the put that list in the agv object
        private async void ShortestPathAsync(int x, int y)
        {
            while (wh.AGVList[0].PointList.Count != 0)
            {
                await Task.Delay(3000);
            }
            Point          point1 = new Point(wh.AGVList[0].PositionX, wh.AGVList[0].PositionY);
            Point          point2 = new Point(x, y);
            PathCalculator path   = new PathCalculator(point1, point2);

            path.CalculatePath();
            wh.AGVList[0].PointList = path.GetPointList();
        }
Beispiel #5
0
 /// <summary>
 /// Calculate a path until reaching a destination
 /// </summary>
 /// <param name="_position">destination to reach</param>
 public void SetDestination(Vector3 _position)
 {
     if (CustomNavMeshManager.Triangles == null || CustomNavMeshManager.Triangles.Count == 0)
     {
         Debug.LogWarning("Triangles Not found. Must build the navmesh for the scene");
         //Destroy(this);
         return;
     }
     if (isMoving)
     {
         StopAllCoroutines();
     }
     pathState = CalculatingState.Calculating;
     if (PathCalculator.CalculatePath(OffsetPosition, _position, currentPath, CustomNavMeshManager.Triangles))
     {
         pathState = CalculatingState.Ready;
         StartCoroutine(FollowPath());
     }
 }