public static IObservable <AssetBundle> GetAssetBundle(Func <UnityWebRequest> callback, Dictionary <string, string> requestHeaderMap = null, IProgress <float> progress = null) { IObservable <AssetBundle> stream = Request( callback(), requestHeaderMap, (DownloadHandlerAssetBundle downloadHandler) => downloadHandler.assetBundle, progress ); if (!Caching.ready) { Observable.EveryUpdate() .Where(_ => Caching.ready) .Take(1) .SelectMany(_ => stream); } return(stream); }
public static IObservable <CollectionRemoveEvent <T> > OnRemove <T>(this IEnumerable <T> collection) { var previousCollection = new List <T>(); return(Observable.EveryUpdate().SelectMany(_ => { var changedItems = previousCollection.Where(item => !collection.Contains(item)).ToList(); var index = 0; var events = changedItems.Select(item => { var evt = new CollectionRemoveEvent <T>(index, item); index += 1; return evt; }); previousCollection = collection.ToList(); return events; })); }
public static IObservable <Unit> OnPlayAsObservable(this SimpleAnimation self, string stateName = DefaultStateName) { return(Observable .Merge( // ストリームの一発目から値を持っている場合 Observable.EveryUpdate() .Select(__ => self[stateName].time) .Take(1) .Where(x => x > 0.0f) .AsUnitObservable() .TakeUntilDestroy(self), // ストリームが 0.0f から変化した場合 Observable.EveryUpdate() .Select(__ => self[stateName].time) .Pairwise() .Where(pair => Mathf.Approximately(pair.Previous, 0.0f) && pair.Current > 0.0f) .AsUnitObservable() .TakeUntilDestroy(self) ) .Share()); }
internal static IObservable <Unit> CreateSubject(InputType inputType, int button) => Observable.EveryUpdate() .Where(_ => inputTable[inputType](button)) .AsUnitObservable();
private static IObservable <Unit> GetOrCreateSubject(KeyEventType keyEventType, KeyCode keyCode) { return(Observable.EveryUpdate().Where(_ => DELEGATE_MAP[keyEventType](keyCode)).AsUnitObservable()); }
internal static IObservable <Unit> CreateSubject(InputType inputType, KeyCode keyCode = KeyCode.None) => Observable.EveryUpdate() .Where(_ => inputTable[inputType](keyCode)) .AsUnitObservable();
private static IObservable <T> Tween <T>(Func <OperatableBase <T> > start, Func <OperatableBase <T> > finish, Func <float> duration, EaseType easeType, LoopType loopType, Action onCompleteTween) where T : struct { T startValue = default(T); T finishValue = default(T); onCompleteTween = onCompleteTween ?? (() => { }); Func <IObserver <T>, IDisposable> returnStartValue = (observer) => { observer.OnNext(startValue); return(null); }; Func <IObserver <T>, IDisposable> returnFinishValue = (observer) => { observer.OnNext(finishValue); return(null); }; IObservable <T> stream = Observable.Empty <TweenInformation <T> >() // Repeat() のために、毎回初期値を生成 .StartWith(() => new TweenInformation <T>(Time.time, start(), finish(), duration(), easeType, out startValue, out finishValue)) // Update のストリームに変換 .SelectMany(information => Observable.EveryUpdate().Do(_ => information.Time = Time.time - information.StartTime).Select(_ => information)) // Tween 時間が処理時間よりも小さい間流し続ける .TakeWhile(information => information.Time <= information.Duration) // 実際の Easing 処理実行 .Select(information => Easing(information.Time, information.Start, (information.Finish - information.Start), information.Duration, information.EaseType).Value) // 最終フレームの値を確実に流すために OnCompleted が来たら値を一つ流すストリームに繋ぐ // 1回分の Tween が終わったらコールバックを呼ぶ .Concat(Observable.Create(returnFinishValue).Take(1).Do(_ => onCompleteTween())); switch (loopType) { case LoopType.None: // Do nothing. break; case LoopType.Repeat: stream = stream.Repeat(); break; case LoopType.PingPong: stream = stream .Concat( Observable.Empty <TweenInformation <T> >() // Repeat() のために、毎回初期値を生成 .StartWith(() => new TweenInformation <T>(Time.time, start(), finish(), duration(), easeType, out startValue, out finishValue)) // Update のストリームに変換 .SelectMany(information => Observable.EveryUpdate().Do(_ => information.Time = Time.time - information.StartTime).Select(_ => information)) // Tween 時間が処理時間よりも小さい間流し続ける .TakeWhile(information => information.Time <= information.Duration) // start と finish を入れ替えて、実際の Easing 処理実行 .Select(information => Easing(information.Time, information.Finish, (information.Start - information.Finish), information.Duration, information.EaseType).Value) // 最終フレームの値を確実に流すために OnCompleted が来たら最終値を一つ流すストリームに繋ぐ // 1回分の Tween が終わったらコールバックを呼ぶ .Concat(Observable.Create(returnStartValue).Take(1).Do(_ => onCompleteTween())) ) .Repeat(); break; case LoopType.Mirror: stream = stream .Concat( Observable.Empty <TweenInformation <T> >() // Repeat() のために、毎回初期値を生成 .StartWith(() => new TweenInformation <T>(Time.time, start(), finish(), duration(), easeType, out startValue, out finishValue)) // Update のストリームに変換 .SelectMany(information => Observable.EveryUpdate().Do(_ => information.Time = Time.time - information.StartTime).Select(_ => information)) // Tween 時間が処理時間よりも小さい間流し続ける .TakeWhile(information => information.Time <= information.Duration) // start と finish を入れ替えて、実際の Easing 処理実行 .Select(information => Easing(information.Time, information.Finish, (information.Start - information.Finish), information.Duration, MirrorEaseTypeMap[information.EaseType]).Value) // 最終フレームの値を確実に流すために OnCompleted が来たら最終値を一つ流すストリームに繋ぐ // 1回分の Tween が終わったらコールバックを呼ぶ .Concat(Observable.Create(returnStartValue).Take(1).Do(_ => onCompleteTween())) ) .Repeat(); break; } return(stream); }
internal static IObservable <float> CreateSubject(InputType inputType, string axisName) => Observable.EveryUpdate() .Select(_ => inputTable[inputType](axisName));