예제 #1
0
        public string GetBytes(string url, EventHandlerHTTPBytes bytesCallback, EventHandlerServiceError onError = null, EventHandlerServiceTimeOut onTimeOut = null, int timeOut = 0)
        {
            HTTPRequest request = new HTTPRequest();
            request.url = url;
            request.transactionId = UCSS.GenerateTransactionId(Common.Md5Sum(url));
            request.bytesCallback = bytesCallback;
            request.onError = onError;
            request.onTimeOut = onTimeOut;
            request.timeOut = timeOut;

            StartCoroutine(RunGetDataCoroutine(request));

            return request.transactionId;
        }
예제 #2
0
 // *** END texture ***
 // *** AssetBundle ***
 public void GetAssetBundle(HTTPRequest request)
 {
     StartCoroutine(RunGetDataCoroutine(request));
 }
예제 #3
0
        private IEnumerator RunPostFormCoroutine(HTTPRequest request)
        {
            if (string.IsNullOrEmpty(request.transactionId))
            {
                request.transactionId = UCSS.GenerateTransactionId(Common.Md5Sum(request.url));
            }
            if (request.timeOut == 0)
            {
                request.timeOut = this.TimeOut;
            }

            this.AddTransaction(request.transactionId, request.url, request, request.timeOut);
            this.SetTransactionStatus(request.transactionId, transactionStatus.sending);

            WWW www = new WWW(request.url, request.formData);

            if (request.threadPriority != ThreadPriority.Normal)
            {
                www.threadPriority = request.threadPriority;
            }

            float lastDownloadProgress = 0.0f;
            float lastUploadProgress = 0.0f;
            while (!www.isDone)
            {
                if (request.downloadProgress != null)
                {
                    float progress = www.progress;
                    if (progress != lastDownloadProgress)
                    {
                        lastDownloadProgress = progress;
                        request.downloadProgress(progress);
                    }
                }
                if (request.uploadProgress != null)
                {
                    float uploadProgress = www.uploadProgress;
                    if (uploadProgress != lastUploadProgress)
                    {
                        lastUploadProgress = uploadProgress;
                        request.uploadProgress(uploadProgress);
                    }
                }
                yield return null;
            }

            if (!this.TransactionValid(request.transactionId))
            {
                Debug.LogWarning("[HTTPProtocol] [RunPostFormCoroutine] transaction [" + request.transactionId + "] finished, but is no longer valid.");
                yield break;
            }

            StartCoroutine(this.DoCallBack(www, request));
        }
예제 #4
0
 // *** END AssetBundle ***
 // *** AudioClip ***
 public void GetAudioClip(HTTPRequest request)
 {
     StartCoroutine(RunGetDataCoroutine(request));
 }
예제 #5
0
 private IEnumerator DoCallBack(WWW www, HTTPRequest request)
 {
     if (string.IsNullOrEmpty(www.error))
     {
         if (request.wwwCallback != null)
         {
             request.wwwCallback(www, request.transactionId);
         }
     #if UNITY_PRO_LICENSE
         else if (request.assetBundleCallback != null)
         {
             request.assetBundleCallback(www.assetBundle, request.transactionId);
         }
         else if (request.movieTextureCallback != null)
         {
             MovieTexture movieTexture = www.movie;
             while (!movieTexture.isReadyToPlay)
             {
                 yield return null;
             }
             request.movieTextureCallback(movieTexture, request.transactionId);
         }
     #endif
         else if (request.audioClipCallback != null)
         {
             request.audioClipCallback(www.audioClip, request.transactionId);
         }
         else if (request.textureCallback != null)
         {
             request.textureCallback(www.texture, request.transactionId);
         }
         else if (request.textureNonReadableCallback != null)
         {
             request.textureNonReadableCallback(www.textureNonReadable, request.transactionId);
         }
         else if (request.stringCallback != null)
         {
             request.stringCallback(www.text, request.transactionId);
         }
         else if (request.bytesCallback != null)
         {
             request.bytesCallback(www.bytes, request.transactionId);
         }
         this.RemoveTransaction(request.transactionId);
     }
     else
     {
         if (request.onError != null)
         {
             request.onError(www.error, request.transactionId);
         }
         this.RemoveTransaction(request.transactionId);
     }
     yield break;
 }
예제 #6
0
        public string PostForm(string url, WWWForm formData, EventHandlerHTTPString stringCallback, EventHandlerServiceError onError = null, EventHandlerServiceTimeOut onTimeOut = null, int timeOut = 0)
        {
            HTTPRequest request = new HTTPRequest();
            request.url = url;
            request.formData = formData;
            request.transactionId = UCSS.GenerateTransactionId(Common.Md5Sum(url));
            request.stringCallback = stringCallback;
            request.onError = onError;
            request.onTimeOut = onTimeOut;
            request.timeOut = timeOut;

            StartCoroutine(RunPostFormCoroutine(request));

            return request.transactionId;
        }
예제 #7
0
        // *** END AudioClip ***

        // *** Movie ***
#if UNITY_PRO_LICENSE && !UNITY_WEBGL
        public void GetMovie(HTTPRequest request)
        {
            request.coroutineFactory = RunGetDataCoroutineFactory(request);
            request.coroutine        = StartCoroutine(request.coroutineFactory());
        }
예제 #8
0
 // *** POST BYTES ***
 public void PostBytes(HTTPRequest request)
 {
     StartCoroutine(RunPostBytesCoroutine(request));
 }
예제 #9
0
        // *** END post bytes ***

        // *** POST FORM ***
        public void PostForm(HTTPRequest request)
        {
            request.coroutineFactory = RunPostFormCoroutineFactory(request);
            request.coroutine        = StartCoroutine(request.coroutineFactory());
        }
예제 #10
0
 // *** END string ***
 // *** TEXTURE ***
 public void GetTexture(HTTPRequest request)
 {
     StartCoroutine(RunGetDataCoroutine(request));
 }
예제 #11
0
        } // RunPostFormCoroutine

        private System.Func <IEnumerator> RunGetAssetBundleCoroutineFactory(HTTPRequest request)
        {
            return(() => this.RunGetAssetBundleCoroutine(request));
        }
예제 #12
0
        private IEnumerator RunPostFormCoroutine(HTTPRequest request)
        {
            if (string.IsNullOrEmpty(request.transactionId))
            {
                request.transactionId = UCSS.GenerateTransactionId(Common.Md5Sum(request.url));
            }
            if (request.timeOut == 0)
            {
                request.timeOut = this.TimeOut;
            }

            if (!this.IsTransactionValid(request.transactionId))
            {
                this.AddTransaction(request.transactionId, request.url, request, request.timeOut);
            }
            this.SetTransactionStatus(request.transactionId, transactionStatus.sending);

            WWW www = null;

            if (request.headers != null && request.formData == null)
            {
                www = new WWW(request.url, null, request.headers);
            }
            else
            {
                if (request.headers != null)
                {
                    www = new WWW(request.url, request.formData.data, request.headers);
                }
                else
                {
                    www = new WWW(request.url, request.formData);
                }
            }

#if !UNITY_WEBGL
            if (request.threadPriority != ThreadPriority.Normal)
            {
                www.threadPriority = request.threadPriority;
            }
#endif
            this.SetTransactionWWW(request.transactionId, www);
            float lastDownloadProgress = 0.0f;
            float lastUploadProgress   = 0.0f;
            while (!www.isDone)
            {
                if (request.downloadProgress != null)
                {
                    float progress = www.progress;
                    if (progress != lastDownloadProgress)
                    {
                        lastDownloadProgress = progress;
                        request.downloadProgress(progress);
                    }
                }
                if (request.uploadProgress != null)
                {
                    float uploadProgress = www.uploadProgress;
                    if (uploadProgress != lastUploadProgress)
                    {
                        lastUploadProgress = uploadProgress;
                        request.uploadProgress(uploadProgress);
                    }
                }
                yield return(null);
            }

            if (!this.IsTransactionValid(request.transactionId))
            {
                Debug.LogWarning("[HTTPProtocol] [RunPostFormCoroutine] transaction [" + request.transactionId + "] finished, but is no longer valid.");
                yield break;
            }

            StartCoroutine(this.DoCallback(www, request));
        } // RunPostFormCoroutine
예제 #13
0
        } // RunPostBytesCoroutine

        private System.Func <IEnumerator> RunPostFormCoroutineFactory(HTTPRequest request)
        {
            return(() => this.RunPostFormCoroutine(request));
        }
예제 #14
0
 public void GetAssetBundleOrCache(HTTPRequest request)
 {
     StartCoroutine(RunGetAssetBundleCoroutine(request));
 }
예제 #15
0
        public string PostBytes(string url, byte[] bytes, Hashtable headers, EventHandlerHTTPString stringCallback, EventHandlerServiceError onError = null, EventHandlerServiceTimeOut onTimeOut = null, int timeOut = 0)
        {
            HTTPRequest request = new HTTPRequest();
            request.url = url;
            request.bytes = bytes;
            request.headers = headers;
            request.transactionId = UCSS.GenerateTransactionId(Common.Md5Sum(url));
            request.stringCallback = stringCallback;
            request.onError = onError;
            request.onTimeOut = onTimeOut;
            request.timeOut = timeOut;

            StartCoroutine(RunPostBytesCoroutine(request));

            return request.transactionId;
        }
예제 #16
0
 // *** END post form ***
 // *** GET BYTES ***
 public void GetBytes(HTTPRequest request)
 {
     StartCoroutine(RunGetDataCoroutine(request));
 }
예제 #17
0
 // *** END post bytes ***
 // *** POST FORM ***
 public void PostForm(HTTPRequest request)
 {
     StartCoroutine(RunPostFormCoroutine(request));
 }
예제 #18
0
 // *** END bytes ***
 // *** STRING ***
 public void GetString(HTTPRequest request)
 {
     StartCoroutine(RunGetDataCoroutine(request));
 }
예제 #19
0
 public void GetAssetBundleOrCache(HTTPRequest request)
 {
     request.coroutineFactory = RunGetAssetBundleCoroutineFactory(request);
     request.coroutine        = StartCoroutine(request.coroutineFactory());
 }