public IPathRequestQuery RequestPathPlan(PathPlanParams pathPlanParams, IPathAgent agent) { if (!m_bInitialized) { UnityEngine.Debug.LogError("PathManagerComponent isn't yet fully intialized. Wait until Start() has been called. Can't call RequestPathPlan."); return(null); } if (m_requestPool.Count == 0) { UnityEngine.Debug.Log("RequestPathPlan failed because it is already servicing the maximum number of requests: " + m_maxNumberOfPlanners.ToString()); return(null); } if (m_pathPlannerPool.AvailableCount == 0) { UnityEngine.Debug.Log("RequestPathPlan failed because it is already servicing the maximum number of path requests: " + m_maxNumberOfPlanners.ToString()); return(null); } // Clamp the start and goal positions within the terrain space, and make sure they are on the floor. pathPlanParams.UpdateStartAndGoalPos(m_terrain.GetValidPathFloorPos(pathPlanParams.StartPos)); // Make sure this agent does not have an active request if (m_activeRequests.Count > 0) { foreach (PathRequest pathRequest in m_activeRequests) { if (pathRequest.Agent.GetHashCode() == agent.GetHashCode()) { System.Diagnostics.Debug.Assert(false, "Each agent can only have one path request at a time."); return(null); } } } // Make sure this agent does not have a completed request if (m_activeRequests.Count > 0) { foreach (PathRequest pathRequest in m_completedRequests) { if (pathRequest.Agent.GetHashCode() == agent.GetHashCode()) { System.Diagnostics.Debug.Assert(false, "Each agent can only have one path request at a time."); return(null); } } } // Create the new request Pool <PathPlanner> .Node pathPlanner = m_pathPlannerPool.Get(); PathRequest request = m_requestPool.Dequeue(); request.Set(pathPlanParams, pathPlanner, agent); m_activeRequests.AddFirst(request); // Start the request int startNodeIndex = m_terrain.GetPathNodeIndex(pathPlanParams.StartPos); int goalNodeIndex = m_terrain.GetPathNodeIndex(pathPlanParams.GoalPos); pathPlanner.Item.StartANewPlan(startNodeIndex, goalNodeIndex); return(request); }