Ejemplo n.º 1
0
    public virtual void OnPathComplete(Path _p)
    {
        ABPath p = _p as ABPath;

        if (p == null) throw new System.Exception("This function only handles ABPaths, do not use special path types");

        // Claim the new path
        // This is used for path pooling
        p.Claim(this);

        // Path couldn't be calculated of some reason.
        // More info in p.errorLog (debug string)
        if (p.error)
        {
            p.Release(this);
            return;
        }
        goalList.Add(new PathDest(p.endPoint, p.GetTotalLength()));

        // Release the previous path
        // This is used for path pooling
        if (path != null) path.Release(this);

        // Replace the old path
        path = p;
    }
 void OnPathComplete(Path p)
 {
     _path = (ABPath)p;
     _path.Claim(this);
     _numWaypoints = _path.vectorPath.Count;
     _isSearching = false;
     _waypointIndex = 1;
 }
Ejemplo n.º 3
0
 public ABPathEndingCondition(ABPath p)
 {
     if (p == null)
     {
         throw new ArgumentNullException("p");
     }
     this.abPath = p;
     this.path = p;
 }
Ejemplo n.º 4
0
 static int GetNewPath(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
         UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2);
         UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 3);
         Pathfinding.ABPath  o    = obj.GetNewPath(arg0, arg1);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 5
0
		public EndingConditionProximity (ABPath p, float maxDistance) : base(p) {
			this.maxDistance = maxDistance;
		}
Ejemplo n.º 6
0
		public ABPathEndingCondition (ABPath p) {
			if (p == null) throw new System.ArgumentNullException("p");
			abPath = p;
			path = p;
		}
Ejemplo n.º 7
0
Archivo: AILerp.cs Proyecto: CCGLP/Fast
	/** Called when a requested path has finished calculation.
	 * A path is first requested by #SearchPath, it is then calculated, probably in the same or the next frame.
	 * Finally it is returned to the seeker which forwards it to this function.\n
	 */
	public virtual void OnPathComplete (Path _p) {
		ABPath p = _p as ABPath;

		if (p == null) throw new System.Exception("This function only handles ABPaths, do not use special path types");

		canSearchAgain = true;

		// Claim the new path
		// This is used for path pooling
		p.Claim(this);

		// Path couldn't be calculated of some reason.
		// More info in p.errorLog (debug string)
		if (p.error) {
			p.Release(this);
			return;
		}

		if (interpolatePathSwitches) {
			ConfigurePathSwitchInterpolation();
		}

		// Release the previous path
		// This is used for path pooling
		if (path != null) path.Release(this);

		// Replace the old path
		path = p;

		// Just for the rest of the code to work, if there is only one waypoint in the path
		// add another one
		if (path.vectorPath != null && path.vectorPath.Count == 1) {
			path.vectorPath.Insert(0, GetFeetPosition());
		}

		targetReached = false;

		// Reset some variables
		ConfigureNewPath();
	}
Ejemplo n.º 8
0
Archivo: AILerp.cs Proyecto: CCGLP/Fast
	public void OnDisable () {
		// Abort calculation of path
		if (seeker != null && !seeker.IsDone()) seeker.GetCurrentPath().Error();

		// Release current path
		if (path != null) path.Release(this);
		path = null;

		// Make sure we receive callbacks when paths complete
		seeker.pathCallback -= OnPathComplete;
	}
Ejemplo n.º 9
0
 /// <summary>
 /// Call this function to start calculating a path.
 ///
 /// callback will be called when the path has completed.
 /// Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
 /// </summary>
 /// <param name="start">The start point of the path</param>
 /// <param name="end">The end point of the path</param>
 /// <param name="callback">The function to call when the path has been calculated</param>
 /// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.NNConstraint.graphMask. This will override #graphMask for this path request.</param>
 public Path StartPath(Vector3 start, Vector3 end, OnPathDelegate callback, GraphMask graphMask)
 {
     return(StartPath(ABPath.Construct(start, end, null), callback, graphMask));
 }
Ejemplo n.º 10
0
    public void OnPathComplete(Path _p)
    {
        if (!_p.error)
        {
            ABPath p = (ABPath)_p;

            lastRepath = Time.time;
            canRepath = true;

            if (!IgnoreUnwalkbales && Vector3.Distance(p.endPoint, p.originalEndPoint) > (MarginTest))
            {
                currentCallback(false);
                currentCallback = null;
                Debug.Log(name + " - Path Error: Calculated path was not reachable. Distance: " + Vector3.Distance(p.endPoint, p.originalEndPoint)
                    + "\nEndPoint " + p.endPoint + "\nOriginalEndpoint: " + p.originalEndPoint);

                currStartPoint = p.startPoint;
                currStartPointOriginal = p.originalStartPoint;
                currEndPoint = p.endPoint;
                currEndPointOriginal = p.originalEndPoint;
            }
            else
            {
                currentCallback(true);
                currentCallback = null;

                path = p;
                //Reset the waypoint counter
                currentWaypoint = 0;
                targetReached = false;
            }
        }
        else
        {
            Debug.Log(name + " - Path Error: Calculated path was not reachable");
            currentCallback(false);
            currentCallback = null;
        }
        isCalculatingPath = false;
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Called when a requested path has finished calculation.
        /// A path is first requested by <see cref="SearchPath"/>, it is then calculated, probably in the same or the next frame.
        /// Finally it is returned to the seeker which forwards it to this function.
        /// </summary>
        protected virtual void OnPathComplete(Path _p)
        {
            ABPath p = _p as ABPath;

            if (p == null)
            {
                throw new System.Exception("This function only handles ABPaths, do not use special path types");
            }

            canSearchAgain = true;

            // Increase the reference count on the path.
            // This is used for path pooling
            p.Claim(this);

            // Path couldn't be calculated of some reason.
            // More info in p.errorLog (debug string)
            if (p.error)
            {
                p.Release(this);
                return;
            }

            if (interpolatePathSwitches)
            {
                ConfigurePathSwitchInterpolation();
            }


            // Replace the old path
            var oldPath = path;

            path             = p;
            reachedEndOfPath = false;

            // Just for the rest of the code to work, if there
            // is only one waypoint in the path add another one
            if (path.vectorPath != null && path.vectorPath.Count == 1)
            {
                path.vectorPath.Insert(0, GetFeetPosition());
            }

            // Reset some variables
            ConfigureNewPath();

            // Release the previous path
            // This is used for path pooling.
            // This is done after the interpolator has been configured in the ConfigureNewPath method
            // as this method would otherwise invalidate the interpolator
            // since the vectorPath list (which the interpolator uses) will be pooled.
            if (oldPath != null)
            {
                oldPath.Release(this);
            }

            if (interpolator.remainingDistance < 0.0001f && !reachedEndOfPath)
            {
                reachedEndOfPath = true;
                OnTargetReached();
            }
        }
        // Token: 0x060026C8 RID: 9928 RVA: 0x001AD370 File Offset: 0x001AB570
        private Vector3 Snap(ABPath path, StartEndModifier.Exactness mode, bool start, out bool forceAddPoint)
        {
            int       num       = start ? 0 : (path.path.Count - 1);
            GraphNode graphNode = path.path[num];
            Vector3   vector    = (Vector3)graphNode.position;

            forceAddPoint = false;
            switch (mode)
            {
            case StartEndModifier.Exactness.SnapToNode:
                return(vector);

            case StartEndModifier.Exactness.Original:
            case StartEndModifier.Exactness.Interpolate:
            case StartEndModifier.Exactness.NodeConnection:
            {
                Vector3 vector2;
                if (start)
                {
                    vector2 = ((this.adjustStartPoint != null) ? this.adjustStartPoint() : path.originalStartPoint);
                }
                else
                {
                    vector2 = path.originalEndPoint;
                }
                switch (mode)
                {
                case StartEndModifier.Exactness.Original:
                    return(this.GetClampedPoint(vector, vector2, graphNode));

                case StartEndModifier.Exactness.Interpolate:
                {
                    GraphNode graphNode2 = path.path[Mathf.Clamp(num + (start ? 1 : -1), 0, path.path.Count - 1)];
                    return(VectorMath.ClosestPointOnSegment(vector, (Vector3)graphNode2.position, vector2));
                }

                case StartEndModifier.Exactness.NodeConnection:
                {
                    this.connectionBuffer = (this.connectionBuffer ?? new List <GraphNode>());
                    Action <GraphNode> action;
                    if ((action = this.connectionBufferAddDelegate) == null)
                    {
                        action = new Action <GraphNode>(this.connectionBuffer.Add);
                    }
                    this.connectionBufferAddDelegate = action;
                    GraphNode graphNode2 = path.path[Mathf.Clamp(num + (start ? 1 : -1), 0, path.path.Count - 1)];
                    graphNode.GetConnections(this.connectionBufferAddDelegate);
                    Vector3 result = vector;
                    float   num2   = float.PositiveInfinity;
                    for (int i = this.connectionBuffer.Count - 1; i >= 0; i--)
                    {
                        GraphNode graphNode3   = this.connectionBuffer[i];
                        Vector3   vector3      = VectorMath.ClosestPointOnSegment(vector, (Vector3)graphNode3.position, vector2);
                        float     sqrMagnitude = (vector3 - vector2).sqrMagnitude;
                        if (sqrMagnitude < num2)
                        {
                            result        = vector3;
                            num2          = sqrMagnitude;
                            forceAddPoint = (graphNode3 != graphNode2);
                        }
                    }
                    this.connectionBuffer.Clear();
                    return(result);
                }
                }
                throw new ArgumentException("Cannot reach this point, but the compiler is not smart enough to realize that.");
            }

            case StartEndModifier.Exactness.ClosestOnNode:
                if (!start)
                {
                    return(path.endPoint);
                }
                return(path.startPoint);

            default:
                throw new ArgumentException("Invalid mode");
            }
        }
Ejemplo n.º 13
0
        /** Called when a requested path has been calculated.
         * A path is first requested by #UpdatePath, it is then calculated, probably in the same or the next frame.
         * Finally it is returned to the seeker which forwards it to this function.
         */
        protected override void OnPathComplete(Path newPath)
        {
            ABPath p = newPath as ABPath;

            if (p == null)
            {
                throw new System.Exception("This function only handles ABPaths, do not use special path types");
            }

            waitingForPathCalculation = false;

            // Increase the reference count on the new path.
            // This is used for object pooling to reduce allocations.
            p.Claim(this);

            // Path couldn't be calculated of some reason.
            // More info in p.errorLog (debug string)
            if (p.error)
            {
                p.Release(this);
                return;
            }

            // Release the previous path.
            if (path != null)
            {
                path.Release(this);
            }

            // Replace the old path
            path = p;

            // Make sure the path contains at least 2 points
            if (path.vectorPath.Count == 1)
            {
                path.vectorPath.Add(path.vectorPath[0]);
            }
            interpolator.SetPath(path.vectorPath);

            var graph = AstarData.GetGraph(path.path[0]) as ITransformedGraph;

            movementPlane = graph != null ? graph.transform : (rotationIn2D ? new GraphTransform(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 270, 90), Vector3.one)) : GraphTransform.identityTransform);

            // Reset some variables
            reachedEndOfPath = false;

            // Simulate movement from the point where the path was requested
            // to where we are right now. This reduces the risk that the agent
            // gets confused because the first point in the path is far away
            // from the current position (possibly behind it which could cause
            // the agent to turn around, and that looks pretty bad).
            interpolator.MoveToLocallyClosestPoint((GetFeetPosition() + p.originalStartPoint) * 0.5f);
            interpolator.MoveToLocallyClosestPoint(GetFeetPosition());

            // Update which point we are moving towards.
            // Note that we need to do this here because otherwise the remainingDistance field might be incorrect for 1 frame.
            // (due to interpolator.remainingDistance being incorrect).
            interpolator.MoveToCircleIntersection2D(position, pickNextWaypointDist, movementPlane);

            var distanceToEnd = remainingDistance;

            if (distanceToEnd <= endReachedDistance)
            {
                reachedEndOfPath = true;
                OnTargetReached();
            }
        }
Ejemplo n.º 14
0
		Vector3 Snap (ABPath path, Exactness mode, bool start, out bool forceAddPoint) {
			var index = start ? 0 : path.path.Count - 1;
			var node = path.path[index];
			var nodePos = (Vector3)node.position;

			forceAddPoint = false;

			switch (mode) {
			case Exactness.ClosestOnNode:
				return GetClampedPoint(nodePos, start ? path.startPoint : path.endPoint, node);
			case Exactness.SnapToNode:
				return nodePos;
			case Exactness.Original:
			case Exactness.Interpolate:
			case Exactness.NodeConnection:
				Vector3 relevantPoint;
				if (start) {
					relevantPoint = adjustStartPoint != null ? adjustStartPoint() : path.originalStartPoint;
				} else {
					relevantPoint = path.originalEndPoint;
				}

				switch (mode) {
				case Exactness.Original:
					return GetClampedPoint(nodePos, relevantPoint, node);
				case Exactness.Interpolate:
					var clamped = GetClampedPoint(nodePos, relevantPoint, node);
					// Adjacent node to either the start node or the end node in the path
					var adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count-1)];
					return VectorMath.ClosestPointOnSegment(nodePos, (Vector3)adjacentNode.position, clamped);
				case Exactness.NodeConnection:
					// This code uses some tricks to avoid allocations
					// even though it uses delegates heavily
					// The connectionBufferAddDelegate delegate simply adds whatever node
					// it is called with to the connectionBuffer
					connectionBuffer = connectionBuffer ?? new List<GraphNode>();
					connectionBufferAddDelegate = connectionBufferAddDelegate ?? (GraphNodeDelegate)connectionBuffer.Add;

					// Adjacent node to either the start node or the end node in the path
					adjacentNode = path.path[Mathf.Clamp(index + (start ? 1 : -1), 0, path.path.Count-1)];

					// Add all neighbours of #node to the connectionBuffer
					node.GetConnections(connectionBufferAddDelegate);
					var bestPos = nodePos;
					var bestDist = float.PositiveInfinity;

					// Loop through all neighbours
					// Do it in reverse order because the length of the connectionBuffer
					// will change during iteration
					for (int i = connectionBuffer.Count - 1; i >= 0; i--) {
						var neighbour = connectionBuffer[i];

						// Find the closest point on the connection between the nodes
						// and check if the distance to that point is lower than the previous best
						var closest = VectorMath.ClosestPointOnSegment(nodePos, (Vector3)neighbour.position, relevantPoint);

						var dist = (closest - relevantPoint).sqrMagnitude;
						if (dist < bestDist) {
							bestPos = closest;
							bestDist = dist;

							// If this node is not the adjacent node
							// then the path should go through the start node as well
							forceAddPoint = neighbour != adjacentNode;
						}
					}

					connectionBuffer.Clear();
					return bestPos;
				default:
					throw new System.ArgumentException("Cannot reach this point, but the compiler is not smart enough to realize that.");
				}
			default:
				throw new System.ArgumentException("Invalid mode");
			}
		}
Ejemplo n.º 15
0
    public void OnRepathComplete(Path _p)
    {
        if (!_p.error)
        {
            ABPath p = (ABPath)_p;

            lastRepath = Time.time;
            canRepath = true;

            path = p;
            //Reset the waypoint counter
            currentWaypoint = 0;
            targetReached = false;
        }
        else
        {
            Debug.Log(name + " - Path Error: Calculated Re-path was not reachable");
        }
        isCalculatingPath = false;
    }
Ejemplo n.º 16
0
 public CEC(ABPath p, int lim)
     : base(p)
 {
     hLimit = lim;
 }
Ejemplo n.º 17
0
 public PathRequest(FungusNode self, FungusNode other)
 {
     this.other = other;
     path = ABPath.Construct (self.transform.position, other.transform.position);
     AstarPath.StartPath (path);
 }
Ejemplo n.º 18
0
 public ABPathEndingCondition(ABPath p)
 {
     if (p == null) throw new System.ArgumentNullException ("Please supply a non-null path");
     abPath = p;
 }
Ejemplo n.º 19
0
 public ABPath GetNewPath(Vector3 start, Vector3 end)
 {
     // Construct a path with start and end points
     return(ABPath.Construct(start, end, null));
 }