コード例 #1
0
        private void OnEnable()
        {
            _cam        = Camera.main.transform;
            _user       = StreamClient.Instance;
            _links      = LinkManager.Instance as LinkManager;
            _plots      = PlotManager.Instance as PlotManager;
            _webclients = WebClientManager.Instance as WebClientManager;

            // use timeout when creating links
            Link.AllModelChange()
            .Where(ev => ev.Model.CreatedBy == _user.Id && ev.ChangedProperties.Contains("CreatedBy"))
            .Subscribe(ev =>
            {
                _isCreatingLink = true;
                ResetProgress();
                ev.Model.CreatedByRx
                .Where(v => v < 0)
                .Take(1)
                .Delay(TimeSpan.FromSeconds(1))
                .Subscribe(v => _isCreatingLink = false, () => _isCreatingLink = false);
            });

            _user.LookingAtIdRx
            .TakeUntilDisable(this)
            .ObserveOnMainThread()
            .Subscribe(_ => ResetProgress());

            _user.LookingAtTypeRx
            .TakeUntilDisable(this)
            .ObserveOnMainThread()
            .Subscribe(_ => ResetProgress());

            Link.AllModelChange()
            .TakeUntilDisable(this)
            .Where(ev => ev.Model.CreatedBy == _user.Id)
            .Subscribe(_ => ResetProgress());

            // disable & reset progress during zen mode
            _user.ZenModeRx
            .TakeUntilDisable(this)
            .Where(v => v && !(_tablet && _tablet.IsVoiceActive))
            .ObserveOnMainThread()
            .Subscribe(_ => ResetProgress());

            Plot.AllModelChange()
            .TakeUntilDisable(this)
            .Where(ev => ev.ChangedProperties.Contains("BoundTo") && _tablet != null && ev.Model.BoundTo == _tablet.Id)
            .Subscribe(_ => ResetProgress());


            WebClient.AllModelChange()
            .TakeUntilDisable(this)
            .Where(ev => ev.ChangedProperties.Contains("Owner"))
            .Subscribe(ev => SearchCurrentTablet());

            Observable.Merge(WebClient.ModelCreated(), WebClient.ModelDestroyed())
            .TakeUntilDisable(this)
            .Subscribe(m => SearchCurrentTablet());
        }