Beispiel #1
0
        /// <summary>
        /// Starts up the planner.
        /// </summary>
        /// <returns>True on success.</returns>
        public bool Enter()
        {
            if (agent.navGroup.query == null)
            {
                return(false);
            }

            NavmeshPoint pos = agent.GetPointSearch(agent.data.position);

            if (pos.polyRef == 0)
            {
                Debug.LogError(string.Format(
                                   "{0}: Could not constrain position to navigation mesh. {1}"
                                   , agent.transform.name, pos.ToString()));

                return(false);
            }

            NavmeshPoint goal = agent.GetPointSearch(agent.data.goal);

            if (goal.polyRef == 0)
            {
                Debug.LogError(string.Format("{0}: Could not constrain goal to navigation mesh. {1}"
                                             , agent.transform.name, goal.ToString()));

                return(false);
            }

            agent.RemoveFromCrowd();
            agent.SetCorridorAssets(true);
            agent.SetPathAssets(false);

            if (agent.PlanCorridor(pos, goal) <= 0)
            {
                Debug.LogError(string.Format("{0}: Could not plan corridor on enter."
                                             , agent.transform.name));

                agent.data.flags &= ~NavFlag.CorridorInUse;
                return(false);
            }

            agent.data.desiredPosition = agent.corridor.Position;
            agent.data.plannerGoal     = agent.corridor.Target;
            agent.data.flags          &= ~(NavFlag.HasNewPosition | NavFlag.HasNewGoal);

            mSpeed             = Mathf.Sqrt(agent.data.desiredSpeedSq);
            mOptimizationTimer = OptimizationFrequency;

            return(true);
        }