예제 #1
0
 private void OnPathNotFound(PathRequest request)
 {
     if (request.m_Requester != null)
     {
         request.m_Requester.OnPathNotFound();
     }
     this.m_ActiveRequests.Remove(request);
     this.m_Requests.Remove(request);
 }
예제 #2
0
        private void OnPathFound(PathRequest request)
        {
            List <Vector3> path = new List <Vector3>(request.m_NavMeshPath.corners);

            if (request.m_Requester != null)
            {
                request.m_Requester.OnPathFound(path, request.m_NavMeshPath.status);
            }
            this.m_ActiveRequests.Remove(request);
        }
예제 #3
0
        public void RequestPath(IPathRequester requester, Vector3 start, Vector3 target, float radius = 0f)
        {
            PathRequest pathRequest = new PathRequest();

            pathRequest.m_Requester   = requester;
            pathRequest.m_Radius      = radius;
            pathRequest.m_StartPos    = start;
            pathRequest.m_TargetPos   = target;
            pathRequest.m_RequestTime = Time.time;
            pathRequest.m_NavMeshPath = new NavMeshPath();
            this.m_Requests.Add(pathRequest);
        }
예제 #4
0
        private void RemoveObsoleteRequests(ref List <PathRequest> requests)
        {
            int i = 0;

            while (i < requests.Count)
            {
                PathRequest pathRequest = requests[i];
                if (Time.time - pathRequest.m_RequestTime >= pathRequest.m_MaxDuration)
                {
                    this.OnPathNotFound(pathRequest);
                }
                else
                {
                    i++;
                }
            }
        }
예제 #5
0
        private void ProcessRequests()
        {
            if (Time.time < this.m_NextProcessPathTime)
            {
                return;
            }
            while (this.m_Requests.Count > 0 && this.m_ActiveRequests.Count < this.m_MaxRequestsPerUpdate)
            {
                PathRequest pathRequest = this.m_Requests[0];
                NavMesh.CalculatePath(pathRequest.m_StartPos, pathRequest.m_TargetPos, AIManager.s_WalkableAreaMask, pathRequest.m_NavMeshPath);
                this.m_ActiveRequests.Add(pathRequest);
                this.m_Requests.Remove(pathRequest);
            }
            int i = 0;

            while (i < this.m_ActiveRequests.Count)
            {
                PathRequest pathRequest = this.m_ActiveRequests[i];
                if (pathRequest.m_Requester == null || pathRequest.m_Requester.GetAI() == null || !pathRequest.m_Requester.GetAI().gameObject.activeSelf || pathRequest.m_NavMeshPath.status == NavMeshPathStatus.PathInvalid)
                {
                    this.OnPathNotFound(pathRequest);
                }
                else if (pathRequest.m_NavMeshPath.status == NavMeshPathStatus.PathComplete || pathRequest.m_NavMeshPath.status == NavMeshPathStatus.PathPartial)
                {
                    if (pathRequest.m_NavMeshPath.corners.Length > 1)
                    {
                        this.OnPathFound(pathRequest);
                    }
                    else
                    {
                        this.OnPathNotFound(pathRequest);
                    }
                }
                else
                {
                    i++;
                }
            }
            this.m_NextProcessPathTime = Time.time * this.m_ProcessPathInterval;
        }