Example #1
0
 private void DispatchDownloadCompletedEvent(UnityHttpResponse response)
 {
     if (DownloadCompleted != null)
     {
         DownloadCompleted.Invoke(this, new DownloadCompletedEventArgs(response));
     }
 }
Example #2
0
 private void OnResult(UnityHttpResponse response)
 {
     if (resultCallback != null)
     {
         resultCallback.Invoke(this, response);
     }
 }
Example #3
0
        private IEnumerator SendRequest()
        {
            if (DownloadInProgress.GetPersistentEventCount() > 0)
            {
                // Need to show progress of response.
                yield return(new WaitForEndOfFrame());

                if (unityWebRequest != null)
                {
                    AsyncOperation op = unityWebRequest.Send();

                    int displayProgress = 0;
                    int toProgress      = 0;

                    while (!op.isDone)
                    {
                        toProgress = (int)op.progress * 100;

                        while (displayProgress < toProgress)
                        {
                            ++displayProgress;
                            long totalLength = (long)unityWebRequest.downloadedBytes * (long)unityWebRequest.downloadProgress;
                            DispatchDownloadInProgressEvent((long)unityWebRequest.downloadedBytes, totalLength, (float)displayProgress / 100);
                            yield return(new WaitForEndOfFrame());
                        }
                    }
                }
            }
            else
            {
                yield return(new WaitForEndOfFrame());

                if (unityWebRequest != null)
                {
                    yield return(unityWebRequest.Send());
                }
            }

            // Handle response.
            if (unityWebRequest != null && unityWebRequest.isError)
            {
                string errorMessage = unityWebRequest.error;
                DispatchErrorReceivedEvent(errorMessage);
                OnError(errorMessage);
            }
            else
            {
                UnityHttpResponse response = CreateHttpResponse();
                DispatchDownloadCompletedEvent(response);
                OnResult(response);
            }

            if (AutoDispose)
            {
                Dispose();
            }
        }