#if LITMOTION_SUPPORT_R3 using R3; namespace LitMotion { public static class LitMotionR3Extensions { /// /// Create the motion as Observable. /// /// The type of value to animate /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// Observable of the created motion. public static Observable ToObservable(this MotionBuilder builder) where TValue : unmanaged where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { var subject = new Subject(); builder.SetCallbackData(subject, static (x, subject) => subject.OnNext(x)); builder.buffer.OnCompleteAction += () => subject.OnCompleted(); builder.buffer.OnCancelAction += () => subject.OnCompleted(); builder.ScheduleMotion(); return subject; } /// /// Create a motion data and bind it to ReactiveProperty. /// /// The type of value to animate /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// Target object that implements IProgress /// Handle of the created motion data. public static MotionHandle BindToReactiveProperty(this MotionBuilder builder, ReactiveProperty reactiveProperty) where TValue : unmanaged where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(reactiveProperty); return builder.Bind(reactiveProperty, static (x, target) => { target.Value = x; }); } /// /// Add this motion handle to R3 CompositeDisposable. /// /// This motion handle /// Target CompositeDisposable /// Behavior when the disposable is disposed public static MotionHandle AddTo(this MotionHandle handle, CompositeDisposable disposable, DisposeBehavior disposeBehavior = DisposeBehavior.Cancel) { disposable.Add(handle.ToDisposable(disposeBehavior)); return handle; } /// /// Add this motion handle to R3 SerialDisposable. /// /// This motion handle /// Target SerialDisposable /// Behavior when the disposable is disposed public static MotionHandle AddTo(this MotionHandle handle, SerialDisposable disposable, DisposeBehavior disposeBehavior = DisposeBehavior.Cancel) { disposable.Disposable = handle.ToDisposable(disposeBehavior); return handle; } /// /// Add this motion handle to R3 DisposableBag. /// /// This motion handle /// Target DisposableBag /// Behavior when the disposable is disposed public static MotionHandle AddTo(this MotionHandle handle, ref DisposableBag disposable, DisposeBehavior disposeBehavior = DisposeBehavior.Cancel) { disposable.Add(handle.ToDisposable(disposeBehavior)); return handle; } /// /// Add this motion handle to R3 DisposableBuilder. /// /// This motion handle /// Target DisposableBuilder /// Behavior when the disposable is disposed public static MotionHandle AddTo(this MotionHandle handle, ref DisposableBuilder disposable, DisposeBehavior disposeBehavior = DisposeBehavior.Cancel) { disposable.Add(handle.ToDisposable(disposeBehavior)); return handle; } } } #endif