Example #1
0
    public bool MoveToPosition(Vector3 targetPosition, float replanInterval)
    {
        NavTargetPos   navTargetPos = new NavTargetPos(targetPosition, PathTerrain);
        PathPlanParams planParams   = new PathPlanParams(transform.position, navTargetPos, replanInterval);

        return(m_pathAgent.RequestPath(planParams));
    }
Example #2
0
    public bool MoveToGameObject(GameObject gameObject, float replanInterval)
    {
        NavTargetGameObject navTargetGameObject = new NavTargetGameObject(gameObject, PathTerrain);
        PathPlanParams      planParams          = new PathPlanParams(transform.position, navTargetGameObject, replanInterval);

        return(m_pathAgent.RequestPath(planParams));
    }
Example #3
0
    public bool RequestPath(PathPlanParams pathPlanParams)
    {
        if (!m_bInitialized)
        {
            return(false);
        }

        m_pathManager.RemoveRequest(m_query);
        m_query = m_pathManager.RequestPathPlan(pathPlanParams, this);
        if (m_query == null)
        {
            return(false);
        }
        return(true);
    }
    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);
    }