Exemple #1
0
    public 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.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 : GraphTransform.identityTransform);
        this.TargetReached = false;
        this.interpolator.MoveToLocallyClosestPoint((this.GetFeetPosition() + abpath.originalStartPoint) * 0.5f, true, true);
        this.interpolator.MoveToLocallyClosestPoint(this.GetFeetPosition(), true, true);
    }
Exemple #2
0
    public 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();
        }
        if (this.path != null)
        {
            this.path.Release(this, false);
        }
        this.path = abpath;
        if (this.path.vectorPath != null && this.path.vectorPath.Count == 1)
        {
            this.path.vectorPath.Insert(0, this.GetFeetPosition());
        }
        this.targetReached = false;
        this.ConfigureNewPath();
    }
Exemple #3
0
    // Update is called once per frame
    protected void Update()
    {
        //base.Update();

        path = ABPath.Construct(this.transform.position, this.GetComponent <EnemyAI>().target.position, null);

        path.traversalProvider = traversalProvider;

        AstarPath.StartPath(path);

        path.BlockUntilCalculated();

        path.Claim(this);


        if (path.error == true)
        {
            Debug.Log("No Path Was Found.");
        }
        else
        {
            Debug.Log("A Path Was Found With: " + path.vectorPath.Count + " Nodes");

            for (int i = 0; i < path.vectorPath.Count - 1; i++)
            {
                Debug.DrawLine(path.vectorPath[i], path.vectorPath[i + 1], Color.red);
            }

            this.GetComponent <Seeker>().StartPath(path.startPoint, path.endPoint, OnPathCompleteCallback);
        }
    }
Exemple #4
0
    /** 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
        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;

        //Reset some variables
        currentWaypointIndex = 0;
        targetReached        = false;

        //The next row can be used to find out if the path could be found or not
        //If it couldn't (error == true), then a message has probably been logged to the console
        //however it can also be got using p.errorLog
        //if (p.error)

        if (closestOnPathCheck)
        {
            Vector3 p1   = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint;
            Vector3 p2   = GetFeetPosition();
            Vector3 dir  = p2 - p1;
            float   magn = dir.magnitude;
            dir /= magn;
            int steps = (int)(magn / pickNextWaypointDist);

#if ASTARDEBUG
            Debug.DrawLine(p1, p2, Color.red, 1);
#endif

            for (int i = 0; i <= steps; i++)
            {
                CalculateVelocity(p1);
                p1 += dir;
            }
        }
    }
Exemple #5
0
 void OnPathComplete(Path p)
 {
     _path = (ABPath)p;
     _path.Claim(this);
     _numWaypoints  = _path.vectorPath.Count;
     _isSearching   = false;
     _waypointIndex = 1;
 }
Exemple #6
0
        /// <summary>
        /// Called when a requested path has finished calculation.
        /// </summary>
        /// <param name="_p">_p.</param>
        /// <description>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.
        /// </description>
        public virtual void OnPathComplete(Path _p)
        {
            ABPath _path = _p as ABPath;

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

            m_CanSearchAgain = true;

            //Claim the new path
            _path.Claim(this);

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

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

            //Replace the old path
            m_Path = _path;

            //Reset some variables
            m_CurrentWaypointIndex = 0;
            m_TargetReached        = false;

            //The next row can be used to find out if the path could be found or not
            //If it couldn't (error == true), then a message has probably been logged to the console
            //however it can also be got using p.errorLog
            //if (p.error)

            if (ClosestOnPathCheck)
            {
                Vector3 _pos_1     = Time.time - m_LastFoundWaypointTime < 0.3f ? m_LastFoundWaypointPosition : _path.originalStartPoint;
                Vector3 _pos_2     = GetFeetPosition();
                Vector3 _direction = _pos_2 - _pos_1;
                float   _magnitude = _direction.magnitude;
                _direction /= _magnitude;
                int _steps = (int)(_magnitude / PickNextWaypointDist);

                for (int i = 0; i <= _steps; i++)
                {
                    CalculateVelocity(_pos_1);
                    _pos_1 += _direction;
                }
            }
        }
Exemple #7
0
    /** 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
        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);

        // REPLACEMENT
        // var graph = AstarData.GetGraph(path.path[0]) as ITransformedGraph;
        // movementPlane = graph != null ? graph.transform : GraphTransform.identityTransform;
        var graphRotation = new Vector3(-90, 0, 0);

        movementPlane = new GraphTransform(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(graphRotation), Vector3.one));

        // 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());
    }
Exemple #8
0
    private void OnPathComplete(Path p)
    {
        if (path != null)
        {
            path.Release(this);
        }

        path = p as ABPath;

        path.Claim(this);
    }
    /** 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;

        // 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();
        }

        // Release the previous path
        // This is used for path pooling.
        // Note that this will invalidate the interpolator
        // since the vectorPath list will be pooled.
        if (path != null)
        {
            path.Release(this);
        }

        // Replace the old path
        path          = p;
        targetReached = 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();
    }
        public void OnPathComplete(Path _p)
        {
            Debug.LogError(gameObject.name);

            ABPath p = _p as ABPath;

            canSearchAgain = true;

            if (path != null)
            {
                path.Release(this);
            }
            path = p;
            p.Claim(this);

            if (p.error)
            {
                wp         = 0;
                vectorPath = null;
                return;
            }


            Vector3 p1 = p.originalStartPoint;
            Vector3 p2 = transform.position;

            p1.y = p2.y;
            float d = (p2 - p1).magnitude;

            wp = 0;

            vectorPath = p.vectorPath;
            Vector3 waypoint;

            if (moveNextDist > 0)
            {
                for (float t = 0; t <= d; t += moveNextDist * 0.6f)
                {
                    wp--;
                    Vector3 pos = p1 + (p2 - p1) * t;

                    do
                    {
                        wp++;
                        waypoint = vectorPath[wp];
                    } while (controller.To2D(pos - waypoint).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                }
            }
        }
Exemple #11
0
    /** 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");
        }

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

        //Claim the new path
        p.Claim(this);

        //Replace the old path
        path = p;

        //Reset some variables
        currentWaypointIndex = 0;
        targetReached        = false;
        canSearchAgain       = true;

        //The next row can be used to find out if the path could be found or not
        //If it couldn't (error == true), then a message has probably been logged to the console
        //however it can also be got using p.errorLog
        //if (p.error)

        if (closestOnPathCheck)
        {
            Vector3 p1   = p.startPoint;
            Vector3 p2   = GetFeetPosition();
            float   magn = Vector3.Distance(p1, p2);
            Vector3 dir  = p2 - p1;
            dir /= magn;
            int steps = (int)(magn / pickNextWaypointDist);
            for (int i = 0; i < steps; i++)
            {
                CalculateVelocity(p1);
                p1 += dir;
            }
        }
    }
Exemple #12
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");
        }

        canSearchAgain = true;

        p.Claim(this);

        if (p.error)
        {
            p.Release(this);
            return;
        }

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

        path = p;

        currentWaypointIndex = 0;
        targetReached        = false;

        if (closestOnPathCheck)
        {
            Vector3 p1   = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint;
            Vector3 p2   = GetFeetPosition();
            Vector3 dir  = p2 - p1;
            float   magn = dir.magnitude;
            dir /= magn;
            int steps = (int)(magn / pickNextWaypointDist);


            for (int i = 0; i <= steps; i++)
            {
                CalculateVelocity(p1);
                p1 += dir;
            }
        }
    }
    public void OnPathComplete(Path p)
    {
        if (p.error)
        {
            Debug.Log("AI: Got Path, Detected error");
            return;
        }

        if (path != null)
        {
            path.Release(gameObject);
        }
        path = p as ABPath;
        path.Claim(gameObject);
        CurrentWaypoint = 0;
        PathHasEnded    = false;
    }
Exemple #14
0
    public void OnPathComplete(Path _p)
    {
        ABPath p = _p as ABPath;

        //
        canSearchAgain = true;
        //
        if (path != null)
        {
            path.Release(this);
        }
        path = p;
        p.Claim(this);
        //
        if (p.error)
        {
            wp         = 0;
            vectorPath = null;
            return;
        }
        //
        Vector3 p1 = p.originalStartPoint;
        Vector3 p2 = transform.position;

        p1.y = p2.y;
        float d = (p2 - p1).magnitude;

        wp = 0;
        //
        vectorPath = p.vectorPath;
        Vector3 waypoint;

        //
        for (float t = 0; t <= d; t += moveNextDist * 0.6f)
        {
            wp--;
            Vector3 pos = p1 + (p2 - p1) * t;

            do
            {
                wp++;
                waypoint   = vectorPath[wp];
                waypoint.y = pos.y;
            } while ((pos - waypoint).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
        }
    }
        // Token: 0x060029B4 RID: 10676 RVA: 0x001C0A58 File Offset: 0x001BEC58
        public void OnPathComplete(Path _p)
        {
            ABPath abpath = _p as ABPath;

            this.canSearchAgain = true;
            if (this.path != null)
            {
                this.path.Release(this, false);
            }
            this.path = abpath;
            abpath.Claim(this);
            if (abpath.error)
            {
                this.wp         = 0;
                this.vectorPath = null;
                return;
            }
            Vector3 originalStartPoint = abpath.originalStartPoint;
            Vector3 position           = base.transform.position;

            originalStartPoint.y = position.y;
            float magnitude = (position - originalStartPoint).magnitude;

            this.wp         = 0;
            this.vectorPath = abpath.vectorPath;
            if (this.moveNextDist > 0f)
            {
                for (float num = 0f; num <= magnitude; num += this.moveNextDist * 0.6f)
                {
                    this.wp--;
                    Vector3 a = originalStartPoint + (position - originalStartPoint) * num;
                    Vector3 b;
                    do
                    {
                        this.wp++;
                        b = this.vectorPath[this.wp];
                    }while (this.controller.To2D(a - b).sqrMagnitude < this.moveNextDist * this.moveNextDist && this.wp != this.vectorPath.Count - 1);
                }
            }
        }
Exemple #16
0
    public virtual void OnPathComplete(Path _p)
    {
        ABPath path = _p as ABPath;

        if (path == null)
        {
            throw new Exception("This function only handles ABPaths, do not use special path types");
        }
        this.canSearchAgain = true;
        path.Claim(this);
        if (path.error)
        {
            path.Release(this, false);
        }
        else
        {
            if (this.path != null)
            {
                this.path.Release(this, false);
            }
            this.path = path;
            this.currentWaypointIndex = 0;
            this.targetReached        = false;
            if (this.closestOnPathCheck)
            {
                Vector3 currentPosition = ((Time.time - this.lastFoundWaypointTime) >= 0.3f) ? path.originalStartPoint : this.lastFoundWaypointPosition;
                Vector3 vector3         = this.GetFeetPosition() - currentPosition;
                float   magnitude       = vector3.magnitude;
                vector3 = (Vector3)(vector3 / magnitude);
                int num2 = (int)(magnitude / this.pickNextWaypointDist);
                for (int i = 0; i <= num2; i++)
                {
                    this.CalculateVelocity(currentPosition);
                    currentPosition += vector3;
                }
            }
        }
    }
Exemple #17
0
    public 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);
            return;
        }
        if (this.path != null)
        {
            this.path.Release(this);
        }
        this.path = abpath;
        this.currentWaypointIndex = 0;
        this.targetReached        = false;
        if (this.closestOnPathCheck)
        {
            Vector3 vector       = (Time.time - this.lastFoundWaypointTime >= 0.3f) ? abpath.originalStartPoint : this.lastFoundWaypointPosition;
            Vector3 feetPosition = this.GetFeetPosition();
            Vector3 vector2      = feetPosition - vector;
            float   magnitude    = vector2.magnitude;
            vector2 /= magnitude;
            int num = (int)(magnitude / this.pickNextWaypointDist);
            for (int i = 0; i <= num; i++)
            {
                this.CalculateVelocity(vector);
                vector += vector2;
            }
        }
    }
        // Token: 0x06002760 RID: 10080 RVA: 0x001ADE98 File Offset: 0x001AC098
        protected override 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.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;
            this.currentWaypointIndex = 0;
            base.reachedEndOfPath     = false;
            if (this.closestOnPathCheck)
            {
                Vector3 vector    = (Time.time - this.lastFoundWaypointTime < 0.3f) ? this.lastFoundWaypointPosition : abpath.originalStartPoint;
                Vector3 vector2   = this.GetFeetPosition() - vector;
                float   magnitude = vector2.magnitude;
                vector2 /= magnitude;
                int num = (int)(magnitude / this.pickNextWaypointDist);
                for (int i = 0; i <= num; i++)
                {
                    this.CalculateVelocity(vector);
                    vector += vector2;
                }
            }
        }
Exemple #19
0
    public override void OnPathComplete(Path _p)
    {
        if (this._self.roleAction != null && !_p.error)
        {
            this._self.roleAction.SetRoleMove(this.walkType);
        }
        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;
        }
        this.currentWaypointIndex = 0;
        this.targetReached        = false;
        if (this.path != null)
        {
            this.currentWaypointIndex = 1;
            this.path.Release(this, false);
        }
        this.path = aBPath;
        if (this._self.entityType == RoleManager.EntityType.EntityType_Self)
        {
            this._self.roleState.AddState(256);
        }
        if (this.path.vectorPath.Count == 0)
        {
            Debug.LogError("find path error: path count is 0");
        }
    }
Exemple #20
0
    void OnPathComplete(Path newPath)
    {
        //异步操作,如果当前这个组件已经enabled = false就不继续往下执行了
        if (!enabled)
        {
            return;
        }

        ABPath p = newPath as ABPath;

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

        p.Claim(this);

        //如果最后一个点不能到达目标点的话,那么玩家跑到最后一个点
        //这样的话就不用删除最后能直达目标点的路径点
        //默认能够到最后目标点
        bool lastEndPointToTarget = true;

        //和上一次算的路径一样时
        if (SamePath(p))
        {
            //路径点目标点一样,不需要继续
            if (endNavPoint == p.originalEndPoint)
            {
                return;
            }

            if (endPathPoint == endNavPoint)
            {
                //上一次寻路的目标点是路点路径的最后一个点时
                //应该是路点路径的最后一个点不能到目标点
                lastEndPointToTarget = NavHelper.CanReachPoint(p.vectorPath[p.vectorPath.Count - 1], p.originalEndPoint, canReachPointLst);
                if (lastEndPointToTarget)
                {
                    //继续接下来的计算
                }
                else
                {
                    //同样不能到,继续跑最后的点
                    return;
                }
            }
            else
            {
                //当正好走到最后一个点时,最后一个点更新
                if (segmentIndex == totalPathPoints.Count - 1)
                {
                    endNavPoint = p.originalEndPoint;
                    totalPathPoints[totalPathPoints.Count - 1] = p.originalEndPoint;
                    _navmeshAgent.SetDestination(p.originalEndPoint);
                }
                else
                {
                    //还没到最后一个点直接替换就可以了
                    totalPathPoints[totalPathPoints.Count - 1] = p.originalEndPoint;
                }
                return;
            }
        }
        if (p.vectorPath.Count <= 0)
        {
            waitingForPathCalculation = false;
            p.Release(this);
            //当前路径不可达
            pathRemainingDistance = -9999;
            return;
        }
        else if (p.vectorPath.Count == 1 || (p.vectorPath.Count == 2 && (p.vectorPath[0] == p.vectorPath[1])))
        {
            totalPathPoints.Clear();
            totalPathPoints.Add(p.vectorPath[0]);
            endPathPoint = p.vectorPath[0];
        }
        else
        {
            endPathPoint = p.vectorPath[p.vectorPath.Count - 1];
            //如果最后一个点不能到达目标点的话,那么玩家跑到最后一个点
            //这样的话就不用删除最后能直达目标点的路径点
            if (canReachPointLst == null)
            {
                canReachPointLst = NavHelper.GetEmptyPath();
            }
            lastEndPointToTarget = NavHelper.CanReachPoint(p.vectorPath[p.vectorPath.Count - 1], p.originalEndPoint, canReachPointLst);

            //按照路径点计算到目标点起始点
            //如果中间点能直接到目标点或起始点
            //删除中间点
            if ((AstarPathGo.Instance.pointNavSetting & AstarPathGo.PointNavModel.NAV_OPEN_MIDDLE_DIRECT_REACH) != 0)
            {
                int startPoint = FindFirstPoint(p);
                int endPoint   = FindEndPoint(p);
                if (lastEndPointToTarget)
                {
                    //能直接到达目标点的最早一个点
                    if (endPoint < p.vectorPath.Count - 1)
                    {
                        p.vectorPath.RemoveRange(endPoint + 1, p.vectorPath.Count - (endPoint + 1));
                    }
                }

                //
                if (startPoint > 0)
                {
                    //能清除的点有重叠,要保留一个
                    if (startPoint >= p.vectorPath.Count - 1)
                    {
                        Vector3 lastPoint = p.vectorPath[p.vectorPath.Count - 1];
                        p.vectorPath.Clear();
                        p.vectorPath.Add(lastPoint);
                    }
                    else
                    {
                        p.vectorPath.RemoveRange(0, startPoint);
                    }
                }
            }

            #region 路点偏移
            if (randomRadius > 0)
            {
                /// 暂时不做路径点偏移
                //float tempRadius = UnityEngine.Random.Range(0, randomRadius);
                //float angle = UnityEngine.Random.Range(0, 2 * Mathf.PI);
                ////第一个点不做偏移
                //for (int i = 1; i < p.vectorPath.Count; i++)
                //{
                //    //float angle = UnityEngine.Random.Range(0, 2 * Mathf.PI);
                //    p.vectorPath[i] = p.vectorPath[i] + new Vector3(Mathf.Cos(angle) * tempRadius, 0, Mathf.Sin(angle) * tempRadius);
                //}
                totalPathPoints.Clear();
                for (int i = 0; i < p.vectorPath.Count; i++)
                {
                    totalPathPoints.Add(p.vectorPath[i]);
                }
            }
            #endregion
        }

        //起始位置附近的点,如果在其实半径范围内计算目标,选离目标最近的
        if (AstarPathGo.Instance.startPointCalc > 0 && totalPathPoints.Count > 0)
        {
            Vector3 pathEndPoint = p.originalEndPoint;
            if (!lastEndPointToTarget)
            {
                pathEndPoint = totalPathPoints[totalPathPoints.Count - 1];
            }

            float min      = 99999999999;
            int   minIndex = -1;
            for (int i = 0; i < totalPathPoints.Count; i++)
            {
                Vector3 dis_end   = pathEndPoint - totalPathPoints[i];
                Vector3 dis_start = totalPathPoints[i] - p.originalStartPoint;
                if (!AstarPathGo.Instance.calcY)
                {
                    dis_end.y   = 0;
                    dis_start.y = 0;
                }
                float curDis = Vector3.SqrMagnitude(dis_end);
                //如果点在范围起始范围之内,才剔除
                if (Vector3.SqrMagnitude(dis_start) < AstarPathGo.Instance.SqrStartPointCalc && curDis < min)
                {
                    if (AstarPathGo.Instance.calcStartCanReach)
                    {
                        if (NavHelper.FastRaycast(totalPathPoints[i], p.originalStartPoint))
                        {
                            min      = curDis;
                            minIndex = i;
                        }
                    }
                    else
                    {
                        min      = curDis;
                        minIndex = i;
                    }
                }
            }
            //将离目标最近的点移除
            if (minIndex > 0)
            {
                totalPathPoints.RemoveRange(0, minIndex + 1);
            }
        }

        p.Release(this);
        _hasPath = true;
        if (lastEndPointToTarget)
        {
            //添加目标点给路点
            totalPathPoints.Add(p.originalEndPoint);
        }

        #region 折返处理
        if ((AstarPathGo.Instance.pointNavSetting & AstarPathGo.PointNavModel.NAV_OPEN_POINT_FIRST_END_DEL) != 0)
        {
            //最后再做折返处理的
            if (totalPathPoints.Count >= 2)
            {
                float point_Angle = Vector3.Angle(totalPathPoints[1] - totalPathPoints[0], p.originalStartPoint - totalPathPoints[0]);
                if (point_Angle <= 90)
                {
                    totalPathPoints.RemoveAt(0);
                }
            }
            if (totalPathPoints.Count >= 2)
            {
                float point_Angle = 360;
                if (totalPathPoints.Count == 2)
                {
                    point_Angle = Vector3.Angle(totalPathPoints[totalPathPoints.Count - 1] - totalPathPoints[totalPathPoints.Count - 2], p.originalStartPoint - totalPathPoints[totalPathPoints.Count - 2]);
                }
                else
                {
                    point_Angle = Vector3.Angle(totalPathPoints[totalPathPoints.Count - 1] - totalPathPoints[totalPathPoints.Count - 2], totalPathPoints[totalPathPoints.Count - 3] - totalPathPoints[totalPathPoints.Count - 2]);
                }
                if (point_Angle <= 90)
                {
                    totalPathPoints.RemoveAt(totalPathPoints.Count - 2);
                }
            }
        }
        #endregion

        endNavPoint = totalPathPoints[totalPathPoints.Count - 1];
        #if UNITY_EDITOR
        _astarSeeker.lastCompletedVectorPath = totalPathPoints;
        #endif
        waitingForPathCalculation = false;
        SetSegmentIndex(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 < endReachedDistance && !reachedEndOfPath)
        {
            reachedEndOfPath = true;
            OnTargetReached();
        }
    }
Exemple #22
0
        public void OnPathComplete(Path _p)
        {
            //Good Game

            /*if(!_p.error)
             * {
             *  for (int i = 0; i < _p.vectorPath.Count; i++)
             *  {
             *      Debug.Log(gameObject.name + "--first--" + i + "--" + IntMath.Int3s2Vector3s(_p.vectorPath)[i]);
             *  }
             * }*/
            ABPath p = _p as ABPath;

            canSearchAgain = true;

            if (path != null)
            {
                path.Release(this);
            }
            path = p;
            p.Claim(this);

            if (p.error)
            {
                wp         = 0;
                vectorPath = null;
                return;
            }


            //Good Game

            /*Vector3 p1 = (Vector3)p.originalStartPoint;
             *          Vector3 p2 = transform.position;*/
            VInt3 p1 = p.originalStartPoint;
            VInt3 p2 = (VInt3)transform.position;

            p1.y = p2.y;
            //GG
            //float d = (p2 - p1).magnitude;
            float d = ((Vector3)(p2 - p1)).magnitude;

            wp = 0;

            //Good Game
            vectorPath = p.vectorPath;
            //vectorPath = IntMath.Int3s2Vector3s(p.vectorPath);
            for (int i = 0; i < vectorPath.Count; i++)
            {
                Debug.Log(gameObject.name + "--path count--" + i + "--" + vectorPath[i]);
            }
            //Good Game
            //Vector3 waypoint;
            VInt3 waypoint;

            if (moveNextDist > 0)
            {
                for (float t = 0; t <= d; t += moveNextDist * 0.6f)
                {
                    wp--;
                    //Good Game
                    //Vector3 pos = p1 + (p2-p1)*t;
                    VInt3 pos = p1 + (p2 - p1) * t;

                    do
                    {
                        wp++;
                        waypoint = vectorPath[wp];
                        //Debug.Log($"--waypoint--{gameObject.name}--{((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude}--{moveNextDist * moveNextDist}");
                    }
                    //Good Game
                    //while (controller.To2D(pos - waypoint).sqrMagnitude < moveNextDist*moveNextDist && wp != vectorPath.Count-1);
                    //while (((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                    while (controller.To2D((pos - waypoint)).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                }
                //Debug.Log($"--waypoint index--{gameObject.name}--{wp}");
            }
            //GG Test
            //wp = 2;
        }
Exemple #23
0
    /** 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)
    {
        //  bSearchStart = false;

        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);
            //unit
            if (unitController != null)
            {
                unitController.TargetFindandPathSearch(EntityType.Defense);
            }
            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;
        //unit
        if (unitController != null)
        {
            unitController.OnTargetFind();
        }

        // Reset some variables
        ConfigureNewPath();
    }
Exemple #24
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.\n
        /// </summary>
        protected override 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");
            }

            waitingForPathCalculation = false;

            //Claim the new path
            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;

            //Reset some variables
            currentWaypointIndex = 0;
            reachedEndOfPath     = false;

            //The next row can be used to find out if the path could be found or not
            //If it couldn't (error == true), then a message has probably been logged to the console
            //however it can also be got using p.errorLog
            //if (p.error)

            if (closestOnPathCheck)
            {
                // 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).
                Vector3 p1   = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint;
                Vector3 p2   = GetFeetPosition();
                Vector3 dir  = p2 - p1;
                float   magn = dir.magnitude;
                dir /= magn;
                int steps = (int)(magn / pickNextWaypointDist);

#if ASTARDEBUG
                Debug.DrawLine(p1, p2, Color.red, 1);
#endif

                for (int i = 0; i <= steps; i++)
                {
                    CalculateVelocity(p1);
                    p1 += dir;
                }
            }
        }