public void MakeRequest(string url, Delegates.AssetServiceCallback requestCallback) { NetworkRequestObject requestObject = new NetworkRequestObject(this, OnRequestCompleted); pendingRequests.Add(requestObject); requestObject.MakeRequest(url, requestCallback); }
protected void AsyncServerRequest(string path, Delegates.AssetServiceCallback requestCallback) { string url = (Configuration.API_URL + path).Replace(@"\", @"/"); Debug.Log("url: " + url); Core.Instance.NetworkService.MakeRequest(url, requestCallback); }
public void DownloadModel(int index, Delegates.AssetServiceCallback callback) { Delegates.AssetServiceCallback requestCallback = (success, message, result) => { Debug.Log("requestCallback"); if (callback != null) { callback(success, message, result); } }; AsyncServerRequest(MODELS_URI + (index.ToString()), requestCallback); }
private IEnumerator Request(Delegates.AssetServiceCallback requestCallback) { pending = true; NetworkEvent.NetworkRequestStart(this); webRequest = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET); webRequest.downloadHandler = new DownloadHandlerBuffer(); #if UNITY_2017_3_OR_NEWER yield return(webRequest.SendWebRequest()); #else yield return(webRequest.Send()); #endif pending = false; OnRequestCompleted(requestCallback); }
private void OnRequestCompleted(Delegates.AssetServiceCallback requestCallback) { Debug.Log("OnRequestCompleted"); if (webRequest != null) { Debug.LogFormat("Size of response is {0}.", webRequest.downloadedBytes); Debug.LogFormat("Size of data is {0}", webRequest.downloadHandler.data.Length.ToString()); webRequestError = webRequest.error; bool hasError = !string.IsNullOrEmpty(webRequestError); if (hasError) { Debug.LogFormat("WWW Error: {0}", webRequestError); KillRequest(); if (requestCallback != null) { requestCallback(false, webRequestError); } } else { Debug.Log("Response has no errors"); Debug.LogFormat("WWW text: {0}", webRequest.downloadHandler.text); Asset response = ParseResponseBody(webRequest.downloadHandler.text); if (requestCallback != null) { requestCallback(true, null, response); } } KillRequest(); } Delete(); }
internal void MakeRequest(string url, Delegates.AssetServiceCallback requestCallback) { this.url = url; coroutineObject.StartCoroutine(Request(requestCallback)); }