예제 #1
0
 public void RequestPath(PathRequest request)
 {
     if (!graphs.ContainsKey(request.unitSize))
     {
         CreateGraph(request.unitSize);
     }
     request.seeker.StartPath(request.start, request.goal, request.callback, GraphMask.FromGraph(graphs[request.unitSize]));
 }
예제 #2
0
 void Update()
 {
     if (Vector3.SqrMagnitude(transform.position - playerTransformSceneReference.Value.position) < sqrRadius)
     {
         seeker.graphMask = GraphMask.FromGraph(highResGraph);
     }
     else
     {
         seeker.graphMask = GraphMask.FromGraph(lowResGraph);
     }
 }
예제 #3
0
파일: ABPath.cs 프로젝트: yutosin/EdgeGame
        /// <summary>Prepares the path. Searches for start and end nodes and does some simple checking if a path is at all possible</summary>
        //!!!!!IMPORTANT: HACKY MODIFICATION IN THIS FUNCTION TO IGNORE POINT GRAPH NODES WHICH WAS CAUSING WONKY
        //BEHAVIORS, SHOULD CHANGE AND FIGURE OUT ROOT ISSUE!!!!
        protected override void Prepare()
        {
            AstarProfiler.StartProfile("Get Nearest");

            //Initialize the NNConstraint
            nnConstraint.tags = enabledTags;
            NNConstraint newConstraint = NNConstraint.Default;

            newConstraint.graphMask = GraphMask.FromGraph(AstarPath.active.data.gridGraph);
            var startNNInfo = AstarPath.active.GetNearest(startPoint, newConstraint);
            //var startNNInfo  = AstarPath.active.GetNearest(startPoint, nnConstraint);

            //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint
            var pathNNConstraint = nnConstraint as PathNNConstraint;

            if (pathNNConstraint != null)
            {
                pathNNConstraint.SetStart(startNNInfo.node);
            }

            startPoint = startNNInfo.position;

            startIntPoint = (Int3)startPoint;
            startNode     = startNNInfo.node;

            if (startNode == null)
            {
                FailWithError("Couldn't find a node close to the start point");
                return;
            }

            if (!CanTraverse(startNode))
            {
                FailWithError("The node closest to the start point could not be traversed");
                return;
            }

            // If it is declared that this path type has an end point
            // Some path types might want to use most of the ABPath code, but will not have an explicit end point at this stage
            if (hasEndPoint)
            {
                // var endNNInfo = AstarPath.active.GetNearest(endPoint, nnConstraint);
                var endNNInfo = AstarPath.active.GetNearest(endPoint, newConstraint);
                endPoint = endNNInfo.position;
                endNode  = endNNInfo.node;

                if (endNode == null)
                {
                    FailWithError("Couldn't find a node close to the end point");
                    return;
                }

                // This should not trigger unless the user has modified the NNConstraint
                if (!CanTraverse(endNode))
                {
                    FailWithError("The node closest to the end point could not be traversed");
                    return;
                }

                // This should not trigger unless the user has modified the NNConstraint
                if (startNode.Area != endNode.Area)
                {
                    FailWithError("There is no valid path to the target");
                    return;
                }

#if !ASTAR_NO_GRID_GRAPH
                // Potentially we want to special case grid graphs a bit
                // to better support some kinds of games
                // If this returns true it will overwrite the
                // endNode, endPoint, hTarget and hTargetNode fields
                if (!EndPointGridGraphSpecialCase(endNNInfo.node))
#endif
                {
                    // Note, other methods assume hTarget is (Int3)endPoint
                    hTarget     = (Int3)endPoint;
                    hTargetNode = endNode;

                    // Mark end node with flag1 to mark it as a target point
                    pathHandler.GetPathNode(endNode).flag1 = true;
                }
            }

            AstarProfiler.EndProfile();
        }