Exemplo n.º 1
0
        static IEnumerator FetchBytes(WWW www, UtyRx.IObserver <byte[]> observer, UtyRx.IProgress <float> reportProgress, CancellationToken cancel)
        {
            using (www)
            {
                while (!www.isDone && !cancel.IsCancellationRequested)
                {
                    if (reportProgress != null)
                    {
                        try
                        {
                            reportProgress.Report(www.progress);
                        }
                        catch (Exception ex)
                        {
                            observer.OnError(ex);
                            yield break;
                        }
                    }
                    yield return(null);
                }

                if (cancel.IsCancellationRequested)
                {
                    yield break;
                }

                if (reportProgress != null)
                {
                    try
                    {
                        reportProgress.Report(www.progress);
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                        yield break;
                    }
                }

                if (!string.IsNullOrEmpty(www.error))
                {
                    observer.OnError(new WWWErrorException(www));
                }
                else
                {
                    observer.OnNext(www.bytes);
                    observer.OnCompleted();
                }
            }
        }
Exemplo n.º 2
0
 public static UtyRx.IObservable <WWW> PostWWW(string url, WWWForm content, UtyRx.IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, content), observer, progress, cancellation)));
 }
Exemplo n.º 3
0
 public static UtyRx.IObservable <WWW> PostWWW(string url, byte[] postData, Hash headers, UtyRx.IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, postData, headers), observer, progress, cancellation)));
 }
Exemplo n.º 4
0
        public static UtyRx.IObservable <byte[]> PostAndGetBytes(string url, WWWForm content, Hash headers, UtyRx.IProgress <float> progress = null)
        {
            var contentHeaders = content.headers;

            return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => FetchBytes(new WWW(url, content.data, MergeHash(contentHeaders, headers)), observer, progress, cancellation)));
        }
Exemplo n.º 5
0
 public static UtyRx.IObservable <byte[]> PostAndGetBytes(string url, byte[] postData, UtyRx.IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => FetchBytes(new WWW(url, postData), observer, progress, cancellation)));
 }
Exemplo n.º 6
0
 public static UtyRx.IObservable <WWW> GetWWW(string url, Hash headers = null, UtyRx.IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, null, (headers ?? new Hash())), observer, progress, cancellation)));
 }
Exemplo n.º 7
0
 public static UtyRx.IObservable <byte[]> GetAndGetBytes(string url, Hash headers = null, UtyRx.IProgress <float> progress = null)
 {
     return(ObservableUnity
            .FromCoroutine <byte[]>((observer, cancellation) =>
                                    FetchBytes(new WWW(url, null, (headers ?? new Hash())), observer, progress, cancellation))
            .SubscribeOn(Scheduler.MainThread)
            .Take(1));
 }
Exemplo n.º 8
0
 public static UtyRx.IObservable <AssetBundle> LoadFromCacheOrDownload(string url, Hash128 hash128, uint crc, UtyRx.IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <AssetBundle>((observer, cancellation) => FetchAssetBundle(WWW.LoadFromCacheOrDownload(url, hash128, crc), observer, progress, cancellation)));
 }