Esempio n. 1
0
 public void InitialiseNavigator(LongPathGrid longGrid)
 {
     if (!initialised) {
         this.longPathGrid = longGrid;
         this.targetPosition = target.position; //For testing
         initialised = true;
     }
 }
Esempio n. 2
0
 public void CreateLongPathGrid(Vector3 gridCentre, Vector2 gridSize, ComputerLane computerLane)
 {
     if (computerLane == ComputerLane.LEFT)
         leftGrid = new LongPathGrid(gridCentre, gridSize, nodeRadius, unwalkableLayer);
     else {
         rightGrid = new LongPathGrid(gridCentre, gridSize, nodeRadius, unwalkableLayer);
         foreach (Navigator navigator in navigators)
             navigator.InitialiseNavigator(rightGrid);
     }
 }
Esempio n. 3
0
    IEnumerator CalculatePath(Vector3 startPosition, Vector3 targetPosition, LongPathGrid longPathGrid)
    {
        Vector3[] waypoints = new Vector3[0];
        bool pathSuccess = false;

        GridNode startNode = longPathGrid.GetGridNodeFromWorldPoint(startPosition);
        GridNode targetNode = longPathGrid.GetGridNodeFromWorldPoint(targetPosition);

        if (targetNode.walkable) {
            Heap<GridNode> openSet = new Heap<GridNode>(longPathGrid.MaxSize);
            HashSet<GridNode> closedSet = new HashSet<GridNode>();

            openSet.Add(startNode);

            while(openSet.Count > 0) {
                GridNode currentNode = openSet.RemoveFirst();

                closedSet.Add(currentNode);

                if (currentNode == targetNode) {
                    pathSuccess = true;
                    break;
                }

                foreach (GridNode neighbour in longPathGrid.GetNeighbours(currentNode)) {
                    if (!neighbour.walkable || closedSet.Contains(neighbour)) {
                        continue;
                    }

                    int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbour);
                    if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) {
                        neighbour.gCost = newMovementCostToNeighbour;
                        neighbour.hCost = GetDistance(neighbour, targetNode);
                        neighbour.parent = currentNode;

                        if(!openSet.Contains(neighbour))
                            openSet.Add(neighbour);
                        else
                            openSet.UpdateItem(neighbour);
                    }
                }
            }
        }
        yield return null;
        if (pathSuccess)
            waypoints = RetracePath(startNode, targetNode);
        navGridManager.FinishProcessingLongPath(waypoints,pathSuccess);
    }
Esempio n. 4
0
 public static void RequestLongPath(Vector3 pathStart, Vector3 pathTarget, LongPathGrid longPathGrid, Action<Vector3,Vector3,Vector3[], bool> callback)
 {
     LongPathRequest newRequest = new LongPathRequest(pathStart, pathTarget, longPathGrid, callback);
     instance.longPathRequestQueue.Enqueue(newRequest);
     instance.TryProcessNext();
 }
Esempio n. 5
0
 public LongPathRequest(Vector3 start, Vector3 target, LongPathGrid grid, Action<Vector3, Vector3, Vector3[], bool> call)
 {
     pathStart = start;
     pathTarget = target;
     longPathGrid = grid;
     callback = call;
 }
Esempio n. 6
0
 public void StartFindPath(Vector3 startPosition, Vector3 targetPosition, LongPathGrid longPathGrid)
 {
     StartCoroutine(CalculatePath(startPosition,targetPosition, longPathGrid));
 }