API reference · 日本語API索引

UniRxMotionExtensions.cs

Runtime/Integrations/UniRx/UniRxMotionExtensions.cs

1 using System;
2 using UniRx;
3 
4 namespace MeatMotion
5 {
6     public static class UniRxMotionExtensions
7     {
8         public static IObservable<float> ToObservable(this FloatMotionBuilder builder)
9             => builder.AsMotionBuilder().ToObservable();
10 
11         public static IObservable<TValue> ToObservable<TValue, TOptions, TAdapter>(this MotionBuilder<TValue, TOptions, TAdapter> builder)
12             where TValue : unmanaged where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter<TValue, TOptions>
13         {
14             var subject = new Subject<TValue>();
15             builder.WithOnCancel(subject.OnCompleted).WithOnComplete(subject.OnCompleted)
16                 .Bind(subject, static (value, stream) => stream.OnNext(value));
17             return subject;
18         }
19 
20         public static MotionHandle BindToReactiveProperty(this FloatMotionBuilder builder, ReactiveProperty<float> reactiveProperty)
21             => builder.AsMotionBuilder().BindToReactiveProperty(reactiveProperty);
22 
23         public static MotionHandle BindToReactiveProperty<TValue, TOptions, TAdapter>(this MotionBuilder<TValue, TOptions, TAdapter> builder, ReactiveProperty<TValue> reactiveProperty)
24             where TValue : unmanaged where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter<TValue, TOptions>
25             => builder.Bind(reactiveProperty ?? throw new ArgumentNullException(nameof(reactiveProperty)), static (v, property) => property.Value = v);
26     }
27 }