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; }
// *** END texture *** // *** AssetBundle *** public void GetAssetBundle(HTTPRequest request) { StartCoroutine(RunGetDataCoroutine(request)); }
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)); }
// *** END AssetBundle *** // *** AudioClip *** public void GetAudioClip(HTTPRequest request) { StartCoroutine(RunGetDataCoroutine(request)); }
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; }
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; }
// *** END AudioClip *** // *** Movie *** #if UNITY_PRO_LICENSE && !UNITY_WEBGL public void GetMovie(HTTPRequest request) { request.coroutineFactory = RunGetDataCoroutineFactory(request); request.coroutine = StartCoroutine(request.coroutineFactory()); }
// *** POST BYTES *** public void PostBytes(HTTPRequest request) { StartCoroutine(RunPostBytesCoroutine(request)); }
// *** END post bytes *** // *** POST FORM *** public void PostForm(HTTPRequest request) { request.coroutineFactory = RunPostFormCoroutineFactory(request); request.coroutine = StartCoroutine(request.coroutineFactory()); }
// *** END string *** // *** TEXTURE *** public void GetTexture(HTTPRequest request) { StartCoroutine(RunGetDataCoroutine(request)); }
} // RunPostFormCoroutine private System.Func <IEnumerator> RunGetAssetBundleCoroutineFactory(HTTPRequest request) { return(() => this.RunGetAssetBundleCoroutine(request)); }
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
} // RunPostBytesCoroutine private System.Func <IEnumerator> RunPostFormCoroutineFactory(HTTPRequest request) { return(() => this.RunPostFormCoroutine(request)); }
public void GetAssetBundleOrCache(HTTPRequest request) { StartCoroutine(RunGetAssetBundleCoroutine(request)); }
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; }
// *** END post form *** // *** GET BYTES *** public void GetBytes(HTTPRequest request) { StartCoroutine(RunGetDataCoroutine(request)); }
// *** END post bytes *** // *** POST FORM *** public void PostForm(HTTPRequest request) { StartCoroutine(RunPostFormCoroutine(request)); }
// *** END bytes *** // *** STRING *** public void GetString(HTTPRequest request) { StartCoroutine(RunGetDataCoroutine(request)); }
public void GetAssetBundleOrCache(HTTPRequest request) { request.coroutineFactory = RunGetAssetBundleCoroutineFactory(request); request.coroutine = StartCoroutine(request.coroutineFactory()); }