#if LITMOTION_SUPPORT_UNIRX using System; using UniRx; namespace LitMotion { /// /// Provides extension methods for UniRx integration. /// public static class LitMotionUniRxExtensions { /// /// Create the motion as IObservable. /// /// 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 IObservable 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.CallbackData.OnCompleteAction += () => subject.OnCompleted(); builder.buffer.CallbackData.OnCancelAction += () => subject.OnCompleted(); var scheduler = builder.buffer.Scheduler; builder.SetMotionData(); builder.Schedule(scheduler, ref builder.buffer.Data, ref builder.buffer.CallbackData); 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.BindWithState(reactiveProperty, static (x, target) => { target.Value = x; }); } } } #endif