Exemplo n.º 1
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <T> observer, IDisposable cancel)
 {
     if (predicate == null)
     {
         return(source.Subscribe(new First(this, observer, cancel)));
     }
     return(source.Subscribe(new First_(this, observer, cancel)));
 }
Exemplo n.º 2
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <TR> observer, IDisposable cancel)
 {
     if (selector != null)
     {
         return(source.Subscribe(new Select(this, observer, cancel)));
     }
     return(source.Subscribe(new Select_(this, observer, cancel)));
 }
Exemplo n.º 3
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <Unit> observer, IDisposable cancel)
 {
     if (onNext != null)
     {
         return(source.Subscribe(new ForEachAsync(this, observer, cancel)));
     }
     return(source.Subscribe(new ForEachAsync_(this, observer, cancel)));
 }
Exemplo n.º 4
0
 public ReadOnlyReactiveProperty(UniRx.IObservable <T> source, T initialValue, bool distinctUntilChanged)
 {
     this.distinctUntilChanged = distinctUntilChanged;
     value = initialValue;
     canPublishValueOnSubscribe = true;
     sourceConnection           = source.Subscribe(new ReadOnlyReactivePropertyObserver(this));
 }
Exemplo n.º 5
0
 public IDisposable Run()
 {
     length = sources.Length;
     if (length == 0)
     {
         OnNext(new T[0]);
         try
         {
             base.observer.OnCompleted();
         }
         finally
         {
             Dispose();
         }
         return(Disposable.Empty);
     }
     completedCount = 0;
     values         = new T[length];
     IDisposable[] array = new IDisposable[length];
     for (int i = 0; i < length; i++)
     {
         UniRx.IObservable <T>     observable = sources[i];
         WhenAllCollectionObserver observer   = new WhenAllCollectionObserver(this, i);
         array[i] = observable.Subscribe(observer);
     }
     return(StableCompositeDisposable.CreateUnsafe(array));
 }
Exemplo n.º 6
0
            public IDisposable Run()
            {
                isFirstSubscribe = true;
                isDisposed       = false;
                isStopped        = false;
                e            = parent.sources.GetEnumerator();
                subscription = new SerialDisposable();
                schedule     = new SingleAssignmentDisposable();
                UniRx.IObservable <Unit> trigger = parent.trigger;
                Action <Unit>            onNext  = delegate
                {
                    lock (gate)
                    {
                        isStopped = true;
                        e.Dispose();
                        subscription.Dispose();
                        schedule.Dispose();
                        base.observer.OnCompleted();
                    }
                };

                UniRx.IObserver <T> observer = base.observer;
                stopper             = trigger.Subscribe(onNext, observer.OnError);
                schedule.Disposable = Scheduler.CurrentThread.Schedule(RecursiveRun);
                return(new CompositeDisposable(schedule, subscription, stopper, Disposable.Create(delegate
                {
                    lock (gate)
                    {
                        isDisposed = true;
                        e.Dispose();
                    }
                })));
            }
Exemplo n.º 7
0
        public IDisposable Subscribe(UniRx.IObserver <TElement> observer)
        {
            IDisposable disposable  = refCount.GetDisposable();
            IDisposable disposable2 = subject.Subscribe(observer);

            return(StableCompositeDisposable.Create(disposable, disposable2));
        }
Exemplo n.º 8
0
 private void RecursiveRun(Action self)
 {
     lock (gate)
     {
         nextSelf = self;
         if (!isDisposed && !isStopped)
         {
             UniRx.IObservable <T> observable = null;
             bool      flag = false;
             Exception ex   = null;
             try
             {
                 flag = e.MoveNext();
                 if (flag)
                 {
                     observable = e.Current;
                     if (observable == null)
                     {
                         throw new InvalidOperationException("sequence is null.");
                     }
                 }
                 else
                 {
                     e.Dispose();
                 }
             }
             catch (Exception ex2)
             {
                 ex = ex2;
                 e.Dispose();
             }
             if (ex != null)
             {
                 stopper.Dispose();
                 observer.OnError(ex);
             }
             else if (!flag)
             {
                 stopper.Dispose();
                 observer.OnCompleted();
             }
             else
             {
                 UniRx.IObservable <T>      current = e.Current;
                 SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable();
                 subscription.Disposable = singleAssignmentDisposable;
                 if (isFirstSubscribe)
                 {
                     isFirstSubscribe = false;
                     singleAssignmentDisposable.Disposable = current.Subscribe(this);
                 }
                 else
                 {
                     MainThreadDispatcher.SendStartCoroutine(SubscribeAfterEndOfFrame(singleAssignmentDisposable, current, this, parent.lifeTimeChecker));
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <T> observer, IDisposable cancel)
 {
     if (scheduler == null)
     {
         return(source.Subscribe(new Skip(this, observer, cancel)));
     }
     return(new Skip_(this, observer, cancel).Run());
 }
Exemplo n.º 10
0
 public IDisposable Subscribe(UniRx.IObserver <U> observer)
 {
     if (observer == null)
     {
         throw new ArgumentNullException("observer");
     }
     return(observable.Subscribe(observer));
 }
Exemplo n.º 11
0
            public override void OnNext(UniRx.IObservable <T> value)
            {
                SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable();

                collectionDisposable.Add(singleAssignmentDisposable);
                Merge observer = new Merge(this, singleAssignmentDisposable);

                singleAssignmentDisposable.Disposable = value.Subscribe(observer);
            }
Exemplo n.º 12
0
            private static IEnumerator SubscribeAfterEndOfFrame(SingleAssignmentDisposable d, UniRx.IObservable <T> source, IObserver <T> observer, GameObject lifeTimeChecker)
            {
                yield return(YieldInstructionCache.WaitForEndOfFrame);

                if (!d.IsDisposed && lifeTimeChecker != null)
                {
                    d.Disposable = source.Subscribe(observer);
                }
            }
Exemplo n.º 13
0
            private void Subscribe(UniRx.IObservable <T> innerSource)
            {
                SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable();

                collectionDisposable.Add(singleAssignmentDisposable);
                Merge observer = new Merge(this, singleAssignmentDisposable);

                singleAssignmentDisposable.Disposable = innerSource.Subscribe(observer);
            }
Exemplo n.º 14
0
        public void Color(UniRx.IObservable <UnityEngine.Color> color)
        {
            var g   = gObject;
            var sub = color.Subscribe((c) =>
            {
                g.titleColor = c;
            });

            uiBase.AddDisposable(sub);
        }
Exemplo n.º 15
0
        protected override IDisposable SubscribeCore(UniRx.IObserver <T> observer, IDisposable cancel)
        {
            if (dueTimeT.HasValue)
            {
                MultipleAssignmentDisposable d = new MultipleAssignmentDisposable();
                TimeSpan dueTime = Scheduler.Normalize(dueTimeT.Value);
                d.Disposable = scheduler.Schedule(dueTime, delegate
                {
                    d.Disposable = source.Subscribe(observer);
                });
                return(d);
            }
            MultipleAssignmentDisposable d2 = new MultipleAssignmentDisposable();

            d2.Disposable = scheduler.Schedule(dueTimeD.Value, (Action) delegate
            {
                d2.Disposable = source.Subscribe(observer);
            });
            return(d2);
        }
Exemplo n.º 16
0
        protected override IDisposable SubscribeCore(UniRx.IObserver <T> observer, IDisposable cancel)
        {
            SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable();
            SerialDisposable           d = new SerialDisposable();

            d.Disposable = singleAssignmentDisposable;
            singleAssignmentDisposable.Disposable = scheduler.Schedule(delegate
            {
                d.Disposable = new ScheduledDisposable(scheduler, source.Subscribe(observer));
            });
            return(d);
        }
Exemplo n.º 17
0
            public override void OnNext(UniRx.IObservable <T> value)
            {
                ulong id = 0uL;

                lock (gate)
                {
                    id        = ++latest;
                    hasLatest = true;
                }
                SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable();

                innerSubscription.Disposable          = singleAssignmentDisposable;
                singleAssignmentDisposable.Disposable = value.Subscribe(new Switch(this, id));
            }
Exemplo n.º 18
0
 public ObservableYieldInstruction(UniRx.IObservable <T> source, bool reThrowOnError, CancellationToken cancel)
 {
     moveNext            = true;
     this.reThrowOnError = reThrowOnError;
     this.cancel         = cancel;
     try
     {
         subscription = source.Subscribe(new ToYieldInstruction(this));
     }
     catch
     {
         moveNext = false;
         throw;
     }
 }
        internal YieldInstruction(UniRx.IObservable <T> source, bool rethrowOnError)
        {
            this.rethrowOnError = rethrowOnError;

            try
            {
                var observer = new ObserverYieldInstruction(this);
                subscription = source.Subscribe(observer);
            }

            catch
            {
                moveNext = false;
                throw;
            }
        }
Exemplo n.º 20
0
 public override void OnCompleted()
 {
     if (seenValue)
     {
         UniRx.IObservable <TResult> observable = parent.selector(lastValue);
         serialDisposable.Disposable = observable.Subscribe(observer);
     }
     else
     {
         try
         {
             observer.OnCompleted();
         }
         finally
         {
             Dispose();
         }
     }
 }
Exemplo n.º 21
0
 public T Run()
 {
     semaphore = new ManualResetEvent(initialState: false);
     using (source.Subscribe(this))
     {
         if (!((!(timeout == InfiniteTimeSpan)) ? semaphore.WaitOne(timeout) : semaphore.WaitOne()))
         {
             throw new TimeoutException("OnCompleted not fired.");
         }
     }
     if (ex != null)
     {
         throw ex;
     }
     if (!seenValue)
     {
         throw new InvalidOperationException("No Elements.");
     }
     return(value);
 }
Exemplo n.º 22
0
 public static IDisposable LogToUnityDebug(this UniRx.IObservable <LogEntry> source)
 {
     return(source.Subscribe(new UnityDebugSink()));
 }
Exemplo n.º 23
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <T> observer, IDisposable cancel)
 {
     return(source.Subscribe(new Synchronize(this, observer, cancel)));
 }
Exemplo n.º 24
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <TimeInterval <T> > observer, IDisposable cancel)
 {
     return(source.Subscribe(new FrameTimeInterval(this, observer, cancel)));
 }
Exemplo n.º 25
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <TResult> observer, IDisposable cancel)
 {
     return(source.Subscribe(new OfType(observer, cancel)));
 }
Exemplo n.º 26
0
 public ReadOnlyReactiveProperty(UniRx.IObservable <T> source)
 {
     sourceConnection = source.Subscribe(new ReadOnlyReactivePropertyObserver(this));
 }
Exemplo n.º 27
0
 public ReadOnlyReactiveProperty(UniRx.IObservable <T> source, T initialValue)
 {
     value = initialValue;
     canPublishValueOnSubscribe = true;
     sourceConnection           = source.Subscribe(new ReadOnlyReactivePropertyObserver(this));
 }
Exemplo n.º 28
0
 public ReadOnlyReactiveProperty(UniRx.IObservable <T> source, bool distinctUntilChanged)
 {
     this.distinctUntilChanged = distinctUntilChanged;
     sourceConnection          = source.Subscribe(new ReadOnlyReactivePropertyObserver(this));
 }
Exemplo n.º 29
0
 protected override IDisposable SubscribeCore(UniRx.IObserver <TSource> observer, IDisposable cancel)
 {
     return(source.Subscribe(new Aggregate(this, observer, cancel)));
 }
Exemplo n.º 30
0
    public FacebookRunner()
    {
        SceneLoader root = SceneLoader.Instance;

        Singleton <PropertyManager> .Instance.AddRootContext(this);

        IsLoggedToFacebook = PersistentSingleton <FacebookAPIService> .Instance.IsLoggedToFB.ToReactiveProperty();

        FacebookEvents = m_fbEventsInternal.AsObservable();
        FacebookEvents.Subscribe(delegate(UniRx.Tuple <FacebookEvent, object> e)
        {
            switch (e.Item1)
            {
            case FacebookEvent.LOGIN_CANCELLED:
            case FacebookEvent.LOGIN_FAILED:
                break;

            case FacebookEvent.NEW_FRIENDS_FETCHED:
                break;

            case FacebookEvent.ADD_FRIEND_REQUEST_ERROR:
                break;

            case FacebookEvent.LOGIN_ATTEMPT:
                HandleLoginAttempt((ILoginResult)e.Item2);
                break;

            case FacebookEvent.LOGIN:
                RequestFBData();
                break;

            case FacebookEvent.MY_DATA:
                HandleMyFBData((MyFacebookData)e.Item2);
                GetAllRequests();
                break;

            case FacebookEvent.FRIEND_DATA:
                HandleFriendFBData((FBPlayer)e.Item2);
                GiftsFetched.OnNext(value: true);
                break;

            case FacebookEvent.ALL_REQUESTS:
                HandleAllRequests((IGraphResult)e.Item2);
                break;

            case FacebookEvent.APP_REQUEST_RESULT:
                HandleAppRequestResult((IAppRequestResult)e.Item2);
                break;

            case FacebookEvent.FRIEND_REQUEST_RESULT:
                HandleFBFriendAppRequest((FBPlayer)e.Item2);
                GiftsFetched.OnNext(value: true);
                break;
            }
        }).AddTo(root);
        GiftConsuming.Subscribe(delegate
        {
            GiftOpenInProgress.Value++;
        }).AddTo(root);
        GiftConsumeFailed.Subscribe(delegate
        {
            GiftOpenInProgress.Value--;
        }).AddTo(root);
        GiftConsumeSuccess.Subscribe(delegate
        {
            GiftOpenInProgress.Value--;
        }).AddTo(root);
        GiftSending.Subscribe(delegate
        {
            GiftSendInProgress.Value++;
        }).AddTo(root);
        GiftSendingFailed.Subscribe(delegate
        {
            GiftSendInProgress.Value--;
        }).AddTo(root);
        GiftSendingSuccess.Subscribe(delegate
        {
            GiftSendInProgress.Value--;
        }).AddTo(root);
        GiftOpenBlocked = (from count in GiftOpenInProgress
                           select count != 0).TakeUntilDestroy(root).ToReadOnlyReactiveProperty();
        GiftSendBlocked = (from count in GiftSendInProgress
                           select count != 0).TakeUntilDestroy(root).ToReadOnlyReactiveProperty();
        GiftOpenAvailable = (from _ in (from _ in GiftOpenInProgress
                                        select true).Merge(GiftsFetched)
                             select UniqueGifts().Count > 0).TakeUntilDestroy(root).ToReadOnlyReactiveProperty();
        GiftSendAvailable = (from _ in (from _ in GiftSendInProgress
                                        select true).Merge(GiftsFetched)
                             select !AreAllPlayersGifted()).TakeUntilDestroy(root).ToReadOnlyReactiveProperty();
        GiftConsumeSuccess.Subscribe(delegate(FacebookGift gift)
        {
            MaybeSendBackGift(m_consumedFrom, gift.FromId);
        }).AddTo(root);
        (from pause in Observable.EveryApplicationPause().StartWith(value: false)
         where !pause && IsLoggedToFacebook.Value
         select pause).Subscribe(delegate
        {
            GetAllRequests();
        }).AddTo(root);
        (from tuple in PlayerData.Instance.LifetimeChunk.CombineLatest(PlayerData.Instance.FBId, (int highscore, string player) => new
        {
            highscore,
            player
        })
         where tuple.player != string.Empty && PersistentSingleton <FacebookAPIService> .Instance.FBPlayers.ContainsKey(tuple.player)
         where tuple.highscore > PersistentSingleton <FacebookAPIService> .Instance.FBPlayers[tuple.player].Highscore
         select tuple).Subscribe(tuple =>
        {
            PersistentSingleton <FacebookAPIService> .Instance.FBPlayers[tuple.player].Highscore = tuple.highscore;
        }).AddTo(root);
        (from e in FacebookEvents
         where e.Item1 == FacebookEvent.LOGIN
         select(AccessToken) e.Item2).Subscribe(delegate(AccessToken access)
        {
            PersistentSingleton <PlayFabService> .Instance.LoggedOnPlayerId.Take(1).Subscribe(delegate
            {
                JSONObject customInfo = PersistentSingleton <PlayFabService> .Instance.GetCustomInfo();
                SyncToFacebook(access, customInfo, delegate(JSONObject json)
                {
                    string a = json.asString("PlayFabId", () => string.Empty);
                    if (a != PersistentSingleton <PlayFabService> .Instance.LoggedOnPlayerId.Value)
                    {
                        PersistentSingleton <PlayFabService> .Instance.ClearCmdQueue();
                        PlayerData.Instance.LastSavedToCloud.Value = 0L;
                        PersistentSingleton <PlayFabService> .Instance.LoggedOnPlayerId.UnpublishValue();
                        PersistentSingleton <PlayFabService> .Instance.ShouldLoginImmediately = true;
                        SceneLoadHelper.LoadInitScene();
                    }
                }, null);
            }).AddTo(root);
        }).AddTo(root);
        (from e in FacebookEvents
         where e.Item1 == FacebookEvent.MY_DATA
         select(from f in ((MyFacebookData)e.Item2).Friends
                where ((Dictionary <string, object>) f).ContainsKey("id")
                select(string)((Dictionary <string, object>) f)["id"]).ToList()).Subscribe(delegate(List <string> list)
        {
            PersistentSingleton <PlayFabService> .Instance.GetPlayFabToFacebookIdMapping(list, delegate(Dictionary <string, string> fbToPf)
            {
                PlayerData.Instance.PlayFabToFBIds.Value = fbToPf;
                UpdateLeaderboards.SetValueAndForceNotify(value: true);
            }, null);
        }).AddTo(root);
        (from logged in IsLoggedToFacebook
         where logged
         select logged).Subscribe(delegate
        {
            OnLoggedIn();
        }).AddTo(root);
    }