예제 #1
0
        IEnumerator _loadCoroutine(string key, Completer completer, Isolate isolate)
        {
            var url = _urlFromKey(key);

            using (var www = UnityWebRequest.Get(url)) {
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        www.SetRequestHeader(header.Key, header.Value);
                    }
                }

                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    completer.completeError(new UIWidgetsError(new List <DiagnosticsNode>()
                    {
                        new ErrorSummary($"Unable to load asset: {key}"),
                        new StringProperty("HTTP status code", www.error)
                    }));
                    yield break;
                }

                var data = www.downloadHandler.data;

                using (Isolate.getScope(isolate)) {
                    completer.complete(data);
                }
            }
        }
예제 #2
0
        IEnumerator _loadCoroutine(string key, Completer completer, Isolate isolate)
        {
            var url = new Uri(key);

            using (var www = UnityWebRequest.Get(url)) {
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        www.SetRequestHeader(header.Key, header.Value);
                    }
                }

                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    completer.completeError(new Exception($"Failed to load from url \"{url}\": {www.error}"));
                    yield break;
                }

                var data = www.downloadHandler.data;

                using (Isolate.getScope(isolate)) {
                    completer.complete(data);
                }
            }
        }