Пример #1
0
        //管理目标位置,有比较的话需要对这个目标进行变更
        private bool HandleNormalPlanning(bool hasNewGoal)
        {
            if (hasNewGoal || !mGoalInRange && theAgent.IsNear(theAgent.desiredPosition.point, mTarget.point))
            {
                //在不变更移动计划的时候,看看能不能走
                if (!SetLocalTarget())
                {
                    if (theAgent.PlanPath(theAgent.desiredPosition, theAgent.plannerGoal) <= 0)
                    {
                        Debug.LogError(string.Format("{0}: Path replan failed. Position: {1}, Goal: {2}"
                                                     , theAgent.transform.name, theAgent.desiredPosition.ToString(), theAgent.plannerGoal.ToString()));
                        return(false);
                    }

                    return(SetLocalTarget());
                }
            }
            else if (mGoalInRange)
            {
                //这个方法根据CritterAI原有的架构来做的,由于这个部分已经被魔改,所以此处可能需要很慎重处理
                if (mAtGoalState == StateNormal)
                {
                    if (Vector3Util.IsInRange(theAgent.desiredPosition.point
                                              , theAgent.plannerGoal.point, 0.12f, theAgent.heightTolerence))
                    {
                        mAtGoalState = StateInRange;
                        theAgent.RemoveFromCrowd();

                        CrowdAgentParams config = theAgent.crowdConfig;
                        config.maxSpeed = 0;

                        theAgent.crowdAgent = theAgent.navGroup.crowd.AddAgent(theAgent.plannerGoal.point, config);

                        theAgent.flags &= ~NavFlag.CrowdConfigUpdated;
                    }
                }
            }
            return(true);
        }
Пример #2
0
        //这里其实算是第二次寻路,为了填充路点坐标的信息
        //如果这次寻路失败了,那么也认为没有路
        private bool SetPathInformation(NavmeshPoint pos, NavmeshPoint goal)
        {
            //simplemove模式的路点信息存也到了navAgent的corridor里面
            //mNavAgent.corridor.Corners
            //theAgent.SetPathAssets(true);


            //下面这些代码的循序非常重要,一定要先算planpath然后是straightpath然后再判断是否返回
            if (theAgent.PlanPath(pos, goal) <= 0)
            {
                return(false);
            }

            theAgent.path.BuildStraightPath(pos, goal, theAgent.navGroup.query);
            //如果这路径是脏的,就认为需要重新寻路
            if (theAgent.path.isDirty)
            {
                theAgent.path.isDirty = false;
                return(false);
            }

            return(true);
        }