// Interval, Timer, Delay, Sample, Throttle, Timeout public static IObservable <Unit> NextFrame(FrameCountType frameCountType = FrameCountType.Update) { return(FromMicroCoroutine <Unit>((observer, cancellation) => NextFrameCore(observer, cancellation), frameCountType)); }
public static IObservable <long> IntervalFrame(int intervalFrameCount, FrameCountType frameCountType = FrameCountType.Update) { return(TimerFrame(intervalFrameCount, intervalFrameCount, frameCountType)); }
/// <summary> /// MicroCoroutine is lightweight, fast coroutine dispatcher. /// IEnumerator supports only yield return null. /// </summary> public static IObservable <T> FromMicroCoroutine <T>(Func <IObserver <T>, IEnumerator> coroutine, FrameCountType frameCountType = FrameCountType.Update) { return(FromMicroCoroutine <T>((observer, cancellationToken) => WrapToCancellableEnumerator(coroutine(observer), cancellationToken), frameCountType)); }
/// <summary> /// MicroCoroutine is lightweight, fast coroutine dispatcher. /// IEnumerator supports only yield return null. /// </summary> public static IObservable <T> FromMicroCoroutine <T>(Func <IObserver <T>, CancellationToken, IEnumerator> coroutine, FrameCountType frameCountType = FrameCountType.Update) { return(new UniRx.Operators.FromMicroCoroutineObservable <T>(coroutine, frameCountType)); }
/// <summary> /// Wait command in during target frame counts. /// </summary> public static IObservable <Unit> BatchFrame(this IObservable <Unit> source, int frameCount, FrameCountType frameCountType) { if (frameCount < 0) { throw new ArgumentException("frameCount must be >= 0, frameCount:" + frameCount); } return(new UniRx.Operators.BatchFrameObservable(source, frameCount, frameCountType)); }
/// <summary> /// MicroCoroutine is lightweight, fast coroutine dispatcher. /// IEnumerator supports only yield return null. /// If publishEveryYield = true then publish OnNext every yield return else return once on enumeration completed. /// </summary> public static IObservable <Unit> FromMicroCoroutine(Func <CancellationToken, IEnumerator> coroutine, bool publishEveryYield = false, FrameCountType frameCountType = FrameCountType.Update) { return(FromMicroCoroutine <Unit>((observer, cancellationToken) => WrapEnumerator(coroutine(cancellationToken), observer, cancellationToken, publishEveryYield), frameCountType)); }
public static IObservable <TSource> ThrottleFirstFrame <TSource>(this IObservable <TSource> source, int frameCount, FrameCountType frameCountType = FrameCountType.Update) { if (frameCount < 0) { throw new ArgumentOutOfRangeException("frameCount"); } return(new UniRx.Operators.ThrottleFirstFrameObservable <TSource>(source, frameCount, frameCountType)); }
public static IObservable <T> DelayFrameSubscription <T>(this IObservable <T> source, int frameCount, FrameCountType frameCountType = FrameCountType.Update) { if (frameCount < 0) { throw new ArgumentOutOfRangeException("frameCount"); } return(new UniRx.Operators.DelayFrameSubscriptionObservable <T>(source, frameCount, frameCountType)); }
public static IObservable <long> TimerFrame(int dueTimeFrameCount, int periodFrameCount, FrameCountType frameCountType = FrameCountType.Update) { return(FromMicroCoroutine <long>((observer, cancellation) => TimerFrameCore(observer, dueTimeFrameCount, periodFrameCount, cancellation), frameCountType)); }
/// <summary> /// MicroCoroutine is lightweight, fast coroutine dispatcher. /// IEnumerator supports only yield return null. /// </summary> public static IObservable <T> FromMicroCoroutine <T>(Func <IObserver <T>, IEnumerator> coroutine, FrameCountType frameCountType = FrameCountType.Update) { return(FromMicroCoroutine <T>((observer, _) => coroutine(observer))); }
/// <summary> /// Publish target property when value is changed. If source is destroyed/destructed, publish OnCompleted. /// </summary> /// <param name="fastDestroyCheck">If true and target is UnityObject, use destroyed check by additional component. It is faster check for lifecycle but needs initial cost.</param> public static IObservable <TProperty> ObserveEveryValueChanged <TSource, TProperty>(this TSource source, Func <TSource, TProperty> propertySelector, FrameCountType frameCountType, IEqualityComparer <TProperty> comparer, bool fastDestroyCheck) where TSource : class { if (source == null) { return(Observable.Empty <TProperty>()); } if (comparer == null) { comparer = UnityEqualityComparer.GetDefault <TProperty>(); } var unityObject = source as UnityEngine.Object; var isUnityObject = source is UnityEngine.Object; if (isUnityObject && unityObject == null) { return(Observable.Empty <TProperty>()); } // MicroCoroutine does not publish value immediately, so publish value on subscribe. if (isUnityObject) { return(ObservableUnity.FromMicroCoroutine <TProperty>((observer, cancellationToken) => { if (unityObject != null) { var firstValue = default(TProperty); try { firstValue = propertySelector((TSource)(object)unityObject); } catch (Exception ex) { observer.OnError(ex); return EmptyEnumerator(); } observer.OnNext(firstValue); return PublishUnityObjectValueChanged(unityObject, firstValue, propertySelector, comparer, observer, cancellationToken, fastDestroyCheck); } else { observer.OnCompleted(); return EmptyEnumerator(); } }, frameCountType)); } else { var reference = new WeakReference(source); source = null; return(ObservableUnity.FromMicroCoroutine <TProperty>((observer, cancellationToken) => { var target = reference.Target; if (target != null) { var firstValue = default(TProperty); try { firstValue = propertySelector((TSource)target); } catch (Exception ex) { observer.OnError(ex); return EmptyEnumerator(); } finally { target = null; } observer.OnNext(firstValue); return PublishPocoValueChanged(reference, firstValue, propertySelector, comparer, observer, cancellationToken); } else { observer.OnCompleted(); return EmptyEnumerator(); } }, frameCountType)); } }
/// <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, FrameCountType frameCountType, IEqualityComparer <TProperty> comparer) where TSource : class { return(ObserveEveryValueChanged(source, propertySelector, frameCountType, comparer, false)); }
/// <summary> /// Publish target property when value is changed. If source is destroyed/destructed, publish OnCompleted. /// </summary> /// <param name="fastDestroyCheck">If true and target is UnityObject, use destroyed check by additional component. It is faster check for lifecycle but needs initial cost.</param> public static IObservable <TProperty> ObserveEveryValueChanged <TSource, TProperty>(this TSource source, Func <TSource, TProperty> propertySelector, FrameCountType frameCountType = FrameCountType.Update, bool fastDestroyCheck = false) where TSource : class { return(ObserveEveryValueChanged(source, propertySelector, frameCountType, UnityEqualityComparer.GetDefault <TProperty>(), fastDestroyCheck)); }