/// <summary> /// Publish target property when value is changed. If source is destroyed/destructed, publish OnCompleted. /// </summary> public static IObservable <TProperty> ObserveEveryValueChanged <TSource, TProperty>(this TSource source, Func <TSource, TProperty> propertySelector) where TSource : class { if (source == null) { return(Observable.Empty <TProperty>()); } var unityObject = source as UnityEngine.Object; var isUnityObject = source is UnityEngine.Object; if (isUnityObject && unityObject == null) { return(Observable.Empty <TProperty>()); } if (isUnityObject) { return(ObservableUnity.FromCoroutine <TProperty>((observer, cancellationToken) => PublishUnityObjectValueChanged(unityObject, propertySelector, observer, cancellationToken))); } else { var reference = new WeakReference(source); source = null; return(ObservableUnity.FromCoroutine <TProperty>((observer, cancellationToken) => PublishPocoValueChanged(reference, propertySelector, observer, cancellationToken))); } }
public static IObservable <string> Get(string url, Hash headers = null, IProgress <float> progress = null) { #if !CONSOLE return(ObservableUnity.FromCoroutine <string>((observer, cancellation) => FetchText(new WWW(url, null, (headers ?? new Hash())), observer, progress, cancellation)) .SubscribeOn(Scheduler.MainThread)); #else var webClient = new WebClient(); var query = Observable.FromEventPattern <DownloadStringCompletedEventHandler, DownloadStringCompletedEventArgs> ( eh => new DownloadStringCompletedEventHandler(eh), eh => webClient.DownloadStringCompleted += eh, eh => webClient.DownloadStringCompleted -= eh ).Select(o => o.EventArgs.Result); webClient.DownloadStringAsync(new Uri(url)); return(query); #endif }
/// <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 <byte[]> PostAndGetBytes(string url, byte[] postData, Hash headers, IProgress <float> progress = null) { return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => FetchBytes(new WWW(url, postData, headers), observer, progress, cancellation))); }
public static IObservable <string> Post(string url, WWWForm content, Hash headers, IProgress <float> progress = null) { var contentHeaders = content.headers; return(ObservableUnity.FromCoroutine <string>((observer, cancellation) => FetchText(new WWW(url, content.data, MergeHash(contentHeaders, headers)), observer, progress, cancellation))); }
public static IObservable <string> Post(string url, WWWForm content, IProgress <float> progress = null) { return(ObservableUnity.FromCoroutine <string>((observer, cancellation) => FetchText(new WWW(url, content), observer, progress, cancellation))); }
public static IObservable <string> Post(string url, byte[] postData, IProgress <float> progress = null) { return(ObservableUnity.FromCoroutine <string>((observer, cancellation) => FetchText(new WWW(url, postData), observer, progress, cancellation))); }
public static IObservable <WWW> GetWWW(string url, Hash headers = null, IProgress <float> progress = null) { return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, null, (headers ?? new Hash())), observer, progress, cancellation))); }
public static IObservable <AssetBundle> LoadFromCacheOrDownload(string url, Hash128 hash128, uint crc, IProgress <float> progress = null) { return(ObservableUnity.FromCoroutine <AssetBundle>((observer, cancellation) => FetchAssetBundle(WWW.LoadFromCacheOrDownload(url, hash128, crc), observer, progress, cancellation))); }