Example #1
0
        public void OnDisable()
        {
            // Abort calculation of path
            if (seeker != null && !seeker.IsDone())
            {
                seeker.GetCurrentPath().Error();
            }

            //Make sure we receive callbacks when paths complete
            seeker.pathCallback -= OnPathComplete;
        }
        /** \copydoc Pathfinding::IAstarAI::SetPath */
        public void SetPath(Path path)
        {
            if (path.PipelineState == PathState.Created)
            {
                // Path has not started calculation yet
                lastRepath     = Time.time;
                canSearchAgain = false;
                seeker.CancelCurrentPathRequest();
                seeker.StartPath(path);
            }
            else if (path.PipelineState == PathState.Returned)
            {
                // Path has already been calculated

                // We might be calculating another path at the same time, and we don't want that path to override this one. So cancel it.
                if (seeker.GetCurrentPath() != path)
                {
                    seeker.CancelCurrentPathRequest();
                }
                else
                {
                    throw new System.ArgumentException("If you calculate the path using seeker.StartPath then this script will pick up the calculated path anyway as it listens for all paths the Seeker finishes calculating. You should not call SetPath in that case.");
                }

                OnPathComplete(path);
            }
            else
            {
                // Path calculation has been started, but it is not yet complete. Cannot really handle this.
                throw new System.ArgumentException("You must call the SetPath method with a path that either has been completely calculated or one whose path calculation has not been started at all. It looks like the path calculation for the path you tried to use has been started, but is not yet finished.");
            }
        }