Пример #1
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();
            }
        }
 void OnPathComplete(Path p)
 {
     _path = (ABPath)p;
     _path.Claim(this);
     _numWaypoints = _path.vectorPath.Count;
     _isSearching = false;
     _waypointIndex = 1;
 }
Пример #3
0
        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;


            if (path.vectorPath != null && path.vectorPath.Count == 1)
            {
                path.vectorPath.Insert(0, GetFeetPosition());
            }

            // Reset some variables
            ConfigureNewPath();


            if (oldPath != null)
            {
                oldPath.Release(this);
            }

            if (interpolator.remainingDistance < 0.0001f && !reachedEndOfPath)
            {
                reachedEndOfPath = true;
                OnTargetReached();
            }
        }
Пример #4
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();
			}
		}
Пример #5
0
        // Token: 0x06002139 RID: 8505 RVA: 0x0018D998 File Offset: 0x0018BB98
        protected override void OnPathComplete(Path newPath)
        {
            ABPath abpath = newPath as ABPath;

            if (abpath == null)
            {
                throw new Exception("This function only handles ABPaths, do not use special path types");
            }
            this.waitingForPathCalculation = false;
            abpath.Claim(this);
            if (abpath.error)
            {
                abpath.Release(this, false);
                return;
            }
            if (this.path != null)
            {
                this.path.Release(this, false);
            }
            this.path = abpath;
            if (this.path.vectorPath.Count == 1)
            {
                this.path.vectorPath.Add(this.path.vectorPath[0]);
            }
            this.interpolator.SetPath(this.path.vectorPath);
            ITransformedGraph transformedGraph = AstarData.GetGraph(this.path.path[0]) as ITransformedGraph;

            this.movementPlane    = ((transformedGraph != null) ? transformedGraph.transform : (this.rotationIn2D ? new GraphTransform(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90f, 270f, 90f), Vector3.one)) : GraphTransform.identityTransform));
            this.reachedEndOfPath = false;
            this.interpolator.MoveToLocallyClosestPoint((this.GetFeetPosition() + abpath.originalStartPoint) * 0.5f, true, true);
            this.interpolator.MoveToLocallyClosestPoint(this.GetFeetPosition(), true, true);
            this.interpolator.MoveToCircleIntersection2D(base.position, this.pickNextWaypointDist, this.movementPlane);
            if (this.remainingDistance <= this.endReachedDistance)
            {
                this.reachedEndOfPath = true;
                this.OnTargetReached();
            }
        }
Пример #6
0
        // Token: 0x060020C8 RID: 8392 RVA: 0x00187724 File Offset: 0x00185924
        protected virtual void OnPathComplete(Path _p)
        {
            ABPath abpath = _p as ABPath;

            if (abpath == null)
            {
                throw new Exception("This function only handles ABPaths, do not use special path types");
            }
            this.canSearchAgain = true;
            abpath.Claim(this);
            if (abpath.error)
            {
                abpath.Release(this, false);
                return;
            }
            if (this.interpolatePathSwitches)
            {
                this.ConfigurePathSwitchInterpolation();
            }
            ABPath abpath2 = this.path;

            this.path             = abpath;
            this.reachedEndOfPath = false;
            if (this.path.vectorPath != null && this.path.vectorPath.Count == 1)
            {
                this.path.vectorPath.Insert(0, this.GetFeetPosition());
            }
            this.ConfigureNewPath();
            if (abpath2 != null)
            {
                abpath2.Release(this, false);
            }
            if (this.interpolator.remainingDistance < 0.0001f && !this.reachedEndOfPath)
            {
                this.reachedEndOfPath = true;
                this.OnTargetReached();
            }
        }
Пример #7
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.
         */
        public 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 : GraphTransform.identityTransform;

            // Reset some variables
            targetReached = 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());

            var distanceToEnd = movementPlane.ToPlane(steeringTarget - position).magnitude + interpolator.remainingDistance;

            if (distanceToEnd <= endReachedDistance)
            {
                targetReached = true;
                OnTargetReached();
            }
        }