Esempio n. 1
0
 public static IObservable <string> Get(string url, IDictionary <string, string> headers = null, IProgress <float> progress = null)
 {
     return
         (ObservableUnity.FromCoroutine <string>(
              (observer, cancellation) =>
              FetchText(UnityWebRequest.Get(url), headers, observer, progress, cancellation)));
 }
Esempio n. 2
0
 public static IObservable <AssetBundle> LoadFromCacheOrDownload(string url, uint version, uint crc, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <AssetBundle>((observer, cancellation) => FetchAssetBundle(UnityWebRequestAssetBundle.GetAssetBundle(url, version, crc), null, observer, progress, cancellation)));
 }
Esempio n. 3
0
 public static IObservable <UnityWebRequest> PostRequest(string url, Dictionary <string, string> postData, IDictionary <string, string> headers, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <UnityWebRequest>((observer, cancellation) => Fetch(UnityWebRequest.Post(url, postData), headers, observer, progress, cancellation)));
 }
Esempio n. 4
0
 public static IObservable <byte[]> PostAndGetBytes(string url, Dictionary <string, string> postData, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => FetchBytes(UnityWebRequest.Post(url, postData), null, observer, progress, cancellation)));
 }
Esempio n. 5
0
 public static IObservable <byte[]> ToBytesObservable(this UnityWebRequest request, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => Fetch(request, null, observer, progress, cancellation)));
 }
 // T: where T : AsyncOperation is ambigious with IObservable<T>.AsObservable
 public static IObservable <T> AsAsyncOperationObservable <T>(this T asyncOperation, IProgress <float> progress = null)
     where T : AsyncOperation
 {
     return(ObservableUnity.FromCoroutine <T>((observer, cancellation) => AsObservableCore(asyncOperation, observer, progress, cancellation)));
 }
 /// <summary>
 /// If you needs return value, use AsAsyncOperationObservable instead.
 /// </summary>
 public static IObservable <AsyncOperation> AsObservable(this AsyncOperation asyncOperation, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <AsyncOperation>((observer, cancellation) => AsObservableCore(asyncOperation, observer, progress, cancellation)));
 }
        public static IObservable <TSource> Catch <TSource>(this IEnumerable <IObservable <TSource> > sources)
        {
            // this code is borrowed from RxOfficial(rx.codeplex.com) and modified
            return(Observable.Create <TSource>(observer =>
            {
                var gate = new object();
                var isDisposed = false;
                var e = sources.GetEnumerator();
                var subscription = new SerialDisposable();
                var lastException = default(Exception);

                var cancelable = Scheduler.CurrentThread.Schedule(self =>
                {
                    lock (gate)
                    {
                        var current = default(IObservable <TSource>);
                        var hasNext = false;
                        var ex = default(Exception);

                        if (!isDisposed)
                        {
                            try
                            {
                                hasNext = e.MoveNext();
                                if (hasNext)
                                {
                                    current = e.Current;
                                }
                                else
                                {
                                    e.Dispose();
                                }
                            }
                            catch (Exception exception)
                            {
                                ex = exception;
                                e.Dispose();
                            }
                        }
                        else
                        {
                            return;
                        }

                        if (ex != null)
                        {
                            observer.OnError(ex);
                            return;
                        }

                        if (!hasNext)
                        {
                            if (lastException != null)
                            {
                                observer.OnError(lastException);
                            }
                            else
                            {
                                observer.OnCompleted();
                            }
                            return;
                        }

                        var d = new SingleAssignmentDisposable();
                        subscription.Disposable = d;
                        d.Disposable = current.Subscribe(observer.OnNext, exception =>
                        {
                            lastException = exception;
                            self();
                        }, observer.OnCompleted);
                    }
                });

                return new CompositeDisposable(subscription, cancelable, Disposable.Create(() =>
                {
                    lock (gate)
                    {
                        e.Dispose();
                        isDisposed = true;
                    }
                }));
            }));
        }
        /// <summary>Catch exception and return Observable.Empty.</summary>
        public static IObservable <TSource> CatchIgnore <TSource>(this IObservable <TSource> source)
        {
            var result = source.Catch <TSource, Exception>(ex => Observable.Empty <TSource>());

            return(result);
        }
Esempio n. 10
0
 // marker for CatchIgnore and Catch avoid iOS AOT problem.
 public static IObservable <TSource> CatchIgnore <TSource>(Exception ex)
 {
     return(Observable.Empty <TSource>());
 }