Пример #1
0
        public static WebRequestQueueOperation QueueRequest(UnityWebRequest request)
        {
            WebRequestQueueOperation queueOperation = new WebRequestQueueOperation(request);

            if (s_ActiveRequests.Count < s_MaxRequest)
            {
                UnityWebRequestAsyncOperation webRequestAsyncOp = null;
                try
                {
                    webRequestAsyncOp = request.SendWebRequest();
                    s_ActiveRequests.Add(webRequestAsyncOp);

                    if (webRequestAsyncOp.isDone)
                    {
                        OnWebAsyncOpComplete(webRequestAsyncOp);
                    }
                    else
                    {
                        webRequestAsyncOp.completed += OnWebAsyncOpComplete;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message);
                }

                queueOperation.Complete(webRequestAsyncOp);
            }
            else
            {
                s_QueuedOperations.Enqueue(queueOperation);
            }

            return(queueOperation);
        }
Пример #2
0
        internal static void WaitForRequestToBeActive(WebRequestQueueOperation request, int millisecondsTimeout)
        {
            var completedRequests = new List <UnityWebRequestAsyncOperation>();

            while (s_QueuedOperations.Contains(request))
            {
                completedRequests.Clear();
                foreach (UnityWebRequestAsyncOperation webRequestAsyncOp in s_ActiveRequests)
                {
                    if (UnityWebRequestUtilities.IsAssetBundleDownloaded(webRequestAsyncOp))
                    {
                        completedRequests.Add(webRequestAsyncOp);
                    }
                }
                foreach (UnityWebRequestAsyncOperation webRequestAsyncOp in completedRequests)
                {
                    bool requestIsActive = s_QueuedOperations.Peek() == request;
                    webRequestAsyncOp.completed -= OnWebAsyncOpComplete;
                    OnWebAsyncOpComplete(webRequestAsyncOp);
                    if (requestIsActive)
                    {
                        return;
                    }
                }
                System.Threading.Thread.Sleep(millisecondsTimeout);
            }
        }
        public static WebRequestQueueOperation QueueRequest(UnityWebRequest request)
        {
            WebRequestQueueOperation queueOperation = new WebRequestQueueOperation(request);

            if (s_ActiveRequests.Count < s_MaxRequest)
            {
                var webRequestAsyncOp = request.SendWebRequest();
                s_ActiveRequests.Add(webRequestAsyncOp);

                if (webRequestAsyncOp.isDone)
                {
                    OnWebAsyncOpComplete(webRequestAsyncOp);
                }
                else
                {
                    webRequestAsyncOp.completed += OnWebAsyncOpComplete;
                }

                queueOperation.Complete(webRequestAsyncOp);
            }
            else
            {
                s_QueuedOperations.Enqueue(queueOperation);
            }

            return(queueOperation);
        }