#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.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