Exemplo n.º 1
0
        /// <inheritdoc />
        public void Setup(IEntity entity)
        {
            var audioSource = entity.GetUnityComponent <AudioSource>();

            _eventSystem.Receive <FootStepSoundEvent>().Subscribe(x => audioSource.PlayOneShot(_footStepSounds.TakeRandom())).AddTo(_disposables);
            _eventSystem.Receive <AttackEvent>().Subscribe(x => audioSource.PlayOneShot(_playerAttackSounds.TakeRandom())).AddTo(_disposables);

            _eventSystem.Receive <PickupEvent>().Subscribe(x =>
            {
                AudioClip pickupSound;

                switch (x.PickupableEntity.GetComponent <FoodComponent>().Type)
                {
                case FoodTypeEnum.Apple:
                    pickupSound = _applePickupSounds.TakeRandom();

                    break;

                case FoodTypeEnum.Soda:
                    pickupSound = _sodaPickupSounds.TakeRandom();

                    break;

                case FoodTypeEnum.Unknown:
                default:

                    throw new ArgumentOutOfRangeException();
                }

                audioSource.PlayOneShot(pickupSound);
            }).AddTo(_disposables);
        }
Exemplo n.º 2
0
        public SystemExecutor(
            IPoolManager poolManager,
            IEventSystem eventSystem,
            IEntityReactionSystemHandler entityReactionSystemHandler,
            IGroupReactionSystemHandler groupReactionSystemHandler,
            ISetupSystemHandler setupSystemHandler,
            IInteractReactionSystemHandler interactReactionSystemHandler,
            IManualSystemHandler manualSystemHandler)
        {
            PoolManager = poolManager;
            EventSystem = eventSystem;
            EntityReactionSystemHandler   = entityReactionSystemHandler;
            GroupReactionSystemHandler    = groupReactionSystemHandler;
            SetupSystemHandler            = setupSystemHandler;
            InteractReactionSystemHandler = interactReactionSystemHandler;
            ManualSystemHandler           = manualSystemHandler;

            var addEntitySubscription       = EventSystem.Receive <EntityAddedEvent>().Subscribe(OnEntityAddedToPool);
            var removeEntitySubscription    = EventSystem.Receive <EntityRemovedEvent>().Subscribe(OnEntityRemovedFromPool);
            var addComponentSubscription    = EventSystem.Receive <ComponentAddedEvent>().Subscribe(OnEntityComponentAdded);
            var removeComponentSubscription = EventSystem.Receive <ComponentRemovedEvent>().Subscribe(OnEntityComponentRemoved);

            _systems = new List <ISystem>();
            _entitySubscribtionsOnSystems = new Dictionary <ISystem, Dictionary <IEntity, SubscriptionToken> >();
            _nonEntitySubscriptions       = new Dictionary <ISystem, SubscriptionToken>();
            _eventSubscriptions           = new List <IDisposable>
            {
                addEntitySubscription,
                removeEntitySubscription,
                addComponentSubscription,
                removeComponentSubscription
            };
        }
Exemplo n.º 3
0
        public SystemExecutor(IPoolManager poolManager, IEventSystem eventSystem,
                              IReactToEntitySystemHandler reactToEntitySystemHandler, IReactToGroupSystemHandler reactToGroupSystemHandler,
                              ISetupSystemHandler setupSystemHandler, IReactToDataSystemHandler reactToDataSystemHandler,
                              IManualSystemHandler manualSystemHandler)
        {
            PoolManager = poolManager;
            EventSystem = eventSystem;
            ReactToEntitySystemHandler = reactToEntitySystemHandler;
            ReactToGroupSystemHandler  = reactToGroupSystemHandler;
            SetupSystemHandler         = setupSystemHandler;
            ReactToDataSystemHandler   = reactToDataSystemHandler;
            ManualSystemHandler        = manualSystemHandler;

            var addEntitySubscription       = EventSystem.Receive <EntityAddedEvent>().Subscribe(OnEntityAddedToPool);
            var removeEntitySubscription    = EventSystem.Receive <EntityRemovedEvent>().Subscribe(OnEntityRemovedFromPool);
            var addComponentSubscription    = EventSystem.Receive <ComponentAddedEvent>().Subscribe(OnEntityComponentAdded);
            var removeComponentSubscription = EventSystem.Receive <ComponentRemovedEvent>().Subscribe(OnEntityComponentRemoved);

            _systems             = new List <ISystem>();
            _systemSubscriptions = new Dictionary <ISystem, IList <SubscriptionToken> >();
            _eventSubscriptions  = new List <IDisposable>
            {
                addEntitySubscription, removeEntitySubscription, addComponentSubscription, removeComponentSubscription
            };
        }
        public void StartSystem(IGroupAccessor group)
        {
            _eventSystem.Receive <ComponentRemovedEvent>()
            .Where(x => x.Component.GetType() == typeof(DestructibleComponent))
            .Subscribe(x => _removeDestructible((DestructibleComponent)x.Component))
            .AddTo(_subscriptions);

            _eventSystem.Receive <ComponentRemovedEvent>()
            .Where(x => x.Component.GetType() == typeof(DestructibleComponent))
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Subscribe(s => {
                AstarPath.active.UpdateGraphs(_destructiblesTilemap.localBounds);
            })
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.START)
            .Subscribe(x =>
            {
                var destructiblesGo   = GameObject.Find("Map/Destructibles");
                _destructiblesTilemap = destructiblesGo.GetComponent <Tilemap>();
                var tilemapGo         = GameObject.Find("Map/Tilemap");
                _tilemapTilemap       = tilemapGo.GetComponent <Tilemap>();
                var aStarGo           = GameObject.Find("Map/A*");
                _aStarAstarPath       = aStarGo.GetComponent <AstarPath>();

                _createDestructibles();
            })
            .AddTo(_subscriptions);
        }
Exemplo n.º 5
0
        public void StartSystem(IGroupAccessor group)
        {
            _eventSystem.Receive <KillEvent>()
            .Where(x => _isEnemy(x.target))
            .Subscribe(x => _reduceEnemies())
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.STOP)
            .Subscribe(x =>
            {
                _subscription.Dispose();
                _resetEnemies();
            })
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.START)
            .Subscribe(x =>
            {
                _subscription = Observable.FromCoroutine(_createEnemies)
                                .Subscribe();
            })
            .AddTo(_subscriptions);
        }
Exemplo n.º 6
0
        public void StartSystem(IGroupAccessor group)
        {
            _eventSystem.Receive <KillEvent>()
            .Where(x => _isEnemy(x.target))
            .Subscribe(x => _totalScore += 100)
            .AddTo(_subscriptions);

            _eventSystem.Receive <ScoreEvent>()
            .Subscribe(x => {
                var coinComponent = x.target.GetComponent <CoinComponent>();
                _totalScore      += coinComponent.score;
            })
            .AddTo(_subscriptions);

            _eventSystem.Receive <KillEvent>()
            .Where(x => _isPlayer(x.target))
            .Subscribe(x => _showRestartPanel(true))
            .AddTo(_subscriptions);

            _pauseToggle.OnValueChangedAsObservable()
            .Subscribe(x => _pause(x))
            .AddTo(_subscriptions);

            _resetBtnButton.OnClickAsObservable()
            .Subscribe(x =>
            {
                _showRestartPanel(false);
                _restartLevel();
            })
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.START)
            .Subscribe(x => _resetAll())
            .AddTo(_subscriptions);

            Observable.Interval(TimeSpan.FromMilliseconds(30))
            .Subscribe(x => {
                _updatePlayerHealth();
                _updateScore();
            })
            .AddTo(_subscriptions);

            this.WaitForScene()
            .Subscribe(x =>
            {
                _resetAll();
            });
        }
Exemplo n.º 7
0
    protected override void ApplicationStarted()
    {
        defaultPool = PoolManager.GetPool();

        var levelBlueprint  = new LevelBlueprint();
        var levelEntity     = defaultPool.CreateEntity(levelBlueprint);
        var player          = defaultPool.CreateEntity(new PlayerBlueprint(_gameConfiguration.StartingFoodPoints));
        var playerView      = player.GetComponent <ViewComponent>();
        var playerComponent = player.GetComponent <PlayerComponent>();
        var levelComponent  = levelEntity.GetComponent <LevelComponent>();

        levelComponent.Level.DistinctUntilChanged()
        .Subscribe(x => {
            playerView.View.transform.position = Vector3.zero;
            SetupLevel(levelComponent);
        });

        _eventSystem.Receive <PlayerKilledEvent>()
        .Delay(TimeSpan.FromSeconds(_gameConfiguration.IntroLength))
        .Subscribe(x =>
        {
            levelBlueprint.UpdateLevel(levelComponent, 1);
            playerComponent.Food.Value = _gameConfiguration.StartingFoodPoints;
            SetupLevel(levelComponent);
        });
    }
Exemplo n.º 8
0
        protected ViewResolverSystem(IEventSystem eventSystem)
        {
            EventSystem = eventSystem;

            _destructionSubscription = EventSystem.Receive <ComponentsRemovedEvent>()
                                       .Where(x => _viewCache.ContainsKey(x.Entity.Id))
                                       .Where(x => x.Components.Any(y => y is ViewComponent))
                                       .Subscribe(x => OnViewRemoved(x.Entity));
        }
        public static IObservable <T> OnEvent <T>(this IEventSystem eventSystem, bool onlyOnMainThread = false)
        {
            IObservable <T> result = null;

            if (typeof(T) == typeof(object) || typeof(ISerializableEvent).IsAssignableFrom(typeof(T)))
            {
                result = eventSystem.Receive(typeof(T)).Select(evt => (T)evt);
            }
            else
            {
                result = eventSystem.Receive <T>();
            }
            if (onlyOnMainThread)
            {
                result = result.ObserveOnMainThread();
            }
            return(result);
        }
        public void SetupSubscriptions()
        {
            _levelComponent.HasLoaded.DistinctUntilChanged(isLoaded => isLoaded)
            .Subscribe(x => _levelImage.SetActive(!_levelComponent.HasLoaded.Value))
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerKilledEvent>()
            .Subscribe(x => _levelComponent.HasLoaded.Value = false)
            .AddTo(_subscriptions);
        }
    public void Start()
    {
        IUIPage page = uiManager.CreateUIPage <ViewModelTest, ModelTest, ViewTest>("PanelTest");

        page.ShowUIPage();
        eventSystem.Receive <TestEvent>().Subscribe(_ =>
        {
            Debug.Log(_.hp);
        });
    }
        private void SetupSubscriptions()
        {
            _levelComponent.Level.DistinctUntilChanged()
            .Subscribe(levelNumber => _levelText.text = $"Day {levelNumber}")
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerKilledEvent>()
            .Subscribe(eventData => _levelText.text = $"After {_levelComponent.Level.Value} days, you starved.")
            .AddTo(_subscriptions);
        }
Exemplo n.º 13
0
        private void SetupSubscriptions()
        {
            _levelComponent.Level.DistinctUntilChanged()
            .Subscribe(levelNumber => _levelText.text = string.Format("Day {0}", levelNumber))
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerKilledEvent>()
            .Subscribe(eventData => _levelText.text = string.Format("After {0} days, you starved.", _levelComponent.Level.Value))
            .AddTo(_subscriptions);
        }
Exemplo n.º 14
0
        public void StartSystem(IGroupAccessor group)
        {
            _eventSystem.Receive <DamageEvent>()
            .Where(x => _isPlayer(x.target))
            .Subscribe(x => _startShake())
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.PAUSE)
            .Subscribe(x => _isPaused = true)
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action != LevelActions.PAUSE)
            .Subscribe(x => _isPaused = false)
            .AddTo(_subscriptions);

            Observable.EveryUpdate()
            .Subscribe(x => _move())
            .AddTo(_subscriptions);
        }
Exemplo n.º 15
0
        public void StartSystem(IObservableGroup group)
        {
            _eventSystem.Receive <FoodPickupEvent>().Subscribe(x => {
                var clips = x.IsSoda ? _drinkSounds.AvailableClips : _foodSounds.AvailableClips;
                PlayOneOf(clips);
            }).AddTo(_subscriptions);

            _eventSystem.Receive <EntityMovedEvent>()
            .Subscribe(x => PlayOneOf(_walkingSounds.AvailableClips))
            .AddTo(_subscriptions);

            _eventSystem.Receive <EnemyHitEvent>()
            .Subscribe(x => PlayOneOf(_playerAttackSounds.AvailableClips))
            .AddTo(_subscriptions);

            _eventSystem.Receive <WallHitEvent>()
            .Subscribe(x => PlayOneOf(_playerAttackSounds.AvailableClips))
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerHitEvent>()
            .Subscribe(x => PlayOneOf(_enemyAttackSounds.AvailableClips))
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerKilledEvent>()
            .Subscribe(x => PlayOneOf(_deathSounds.AvailableClips))
            .AddTo(_subscriptions);
        }
        private void SetupSubscriptions()
        {
            _playerComponent.Food.DistinctUntilChanged()
            .Subscribe(foodAmount => { _foodText.text = string.Format("Food: {0}", foodAmount); })
            .AddTo(_subscriptions);

            _eventSystem.Receive <FoodPickupEvent>()
            .Subscribe(x =>
            {
                var foodPoints = x.Food.GetComponent <FoodComponent>().FoodAmount;
                _foodText.text = string.Format("+{0} Food: {1}", foodPoints, _playerComponent.Food.Value);
            })
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerHitEvent>()
            .Subscribe(x =>
            {
                var attackScore = x.Enemy.GetComponent <EnemyComponent>().EnemyPower;
                _foodText.text  = string.Format("-{0} Food: {1}", attackScore, _playerComponent.Food.Value);
            })
            .AddTo(_subscriptions);
        }
Exemplo n.º 17
0
        public void StartSystem(IGroupAccessor group)
        {
            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.PAUSE)
            .Subscribe(x => Time.timeScale = 0.00001f)
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.RESUME)
            .Subscribe(x => Time.timeScale = 1)
            .AddTo(_subscriptions);

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.RESTART)
            .Subscribe(x => _restartLevel())
            .AddTo(_subscriptions);

            this.WaitForScene()
            .Subscribe(x =>
            {
                _startLevel();
            });
        }
Exemplo n.º 18
0
        private void SetupSubscriptions()
        {
            _playerComponent.Food.DistinctUntilChanged()
            .Subscribe(foodAmount => { _foodText.text = $"Food: {foodAmount}"; })
            .AddTo(_subscriptions);

            _eventSystem.Receive <FoodPickupEvent>()
            .Subscribe(x =>
            {
                var foodComponent = x.Food.GetComponent <FoodComponent>();
                var foodPoints    = foodComponent.FoodAmount;
                _foodText.text    = $"+{foodPoints} Food: {_playerComponent.Food.Value}";
            })
            .AddTo(_subscriptions);

            _eventSystem.Receive <PlayerHitEvent>()
            .Subscribe(x =>
            {
                var attackScore = x.Enemy.GetComponent <EnemyComponent>().EnemyPower;
                _foodText.text  = $"-{attackScore} Food: {_playerComponent.Food.Value}";
            })
            .AddTo(_subscriptions);
        }
Exemplo n.º 19
0
        protected ViewHandler(IPoolManager poolManager, IEventSystem eventSystem, IInstantiator instantiator)
        {
            PoolManager  = poolManager;
            EventSystem  = eventSystem;
            Instantiator = instantiator;

            _viewCache = new Dictionary <Guid, GameObject>();

            _destructionSubscription = EventSystem.Receive <ComponentRemovedEvent>()
                                       .Where(x => x.Component is ViewComponent && _viewCache.ContainsKey(x.Entity.Id))
                                       .Subscribe(x =>
            {
                var view = _viewCache[x.Entity.Id];
                _viewCache.Remove(x.Entity.Id);
                DestroyView(view);
            });
        }
Exemplo n.º 20
0
        private void SetupSubscriptions()
        {
            _eventSystem.Receive <PlayerKilledEvent>()
            .Subscribe(x => _musicSource.Stop())
            .AddTo(_subscriptions);

            _levelComponent.HasLoaded
            .DistinctUntilChanged(hasLoaded => hasLoaded)
            .Subscribe(x =>
            {
                if (!_musicSource.isPlaying)
                {
                    _musicSource.Play();
                }
            })
            .AddTo(_subscriptions);
        }
Exemplo n.º 21
0
        public void Setup(IEntity entity)
        {
            var view = entity.GetGameObject();

            view.OnDestroyAsObservable().Subscribe(x =>
            {
                entityDatabase.RemoveEntity(entity);
            }).AddTo(subscriptions);

            eventSystem.Receive <ContentLoadedEvent>().Subscribe(evt =>
            {
                var info = entity.GetComponent <ContentInfo>();
                eventSystem.Publish(new ContentSetupEvent()
                {
                    Info = info
                });
            }).AddTo(subscriptions);
        }
        protected PooledViewResolverSystem(IPoolManager poolManager, IEventSystem eventSystem)
        {
            PoolManager = poolManager;
            EventSystem = eventSystem;

            PrefabTemplate = ResolvePrefabTemplate();

            EventSystem.Receive <EntityRemovedEvent>()
            .Subscribe(x =>
            {
                GameObject view;
                if (_views.TryGetValue(x.Entity, out view))
                {
                    RecycleView(view);
                    _views.Remove(x.Entity);
                }
            });
        }
Exemplo n.º 23
0
        protected PooledViewResolverSystem(IPoolManager poolManager, IEventSystem eventSystem, IInstantiator instantiator)
        {
            PoolManager  = poolManager;
            Instantiator = instantiator;
            EventSystem  = eventSystem;

            _viewCache = new Dictionary <Guid, GameObject>();

            _entitySubscription = EventSystem
                                  .Receive <ComponentRemovedEvent>()
                                  .Where(x => x.Component is ViewComponent && _viewCache.ContainsKey(x.Entity.Id))
                                  .Subscribe(x =>
            {
                var view = _viewCache[x.Entity.Id];
                RecycleView(view);
                _viewCache.Remove(x.Entity.Id);
            });

            PrefabTemplate = ResolvePrefabTemplate();
        }
Exemplo n.º 24
0
        public BulletCollisionSystem(IPoolManager poolManager, IEventSystem eventSystem)
        {
            _pool        = poolManager.GetPool("");
            _eventSystem = eventSystem;

            _destructiblesAccessor = poolManager
                                     .CreateGroupAccessor(new Group(
                                                              typeof(DestructibleComponent)
                                                              ));
            _subscriptions = new List <IDisposable>();

            _eventSystem.Receive <LevelEvent>()
            .Where(x => x.action == LevelActions.START)
            .Subscribe(x =>
            {
                var destructiblesGo   = GameObject.Find("Map/Destructibles");
                _destructiblesTilemap = destructiblesGo.GetComponent <Tilemap>();
            })
            .AddTo(_subscriptions);
        }
        /// <inheritdoc />
        public void Setup(IEntity entity)
        {
            var hitPointComponent = entity.GetComponent <HitPointComponent>();

            var onCollisionStream = entity.GetGameObject().OnCollisionStay2DAsObservable();
            var onAttackStream    = _eventSystem.Receive <AttackEvent>();

            onCollisionStream.Zip(onAttackStream,
                                  (onCollision, attackEvent) => new
            {
                attackEvent,
                onCollision
            })
            .Where(x => x.attackEvent.AttackingEntity == x.onCollision.otherCollider.gameObject.GetComponent <EntityView>().Entity)
            .Subscribe(x =>
            {
                hitPointComponent.HitPoint.Value -= x.attackEvent.Damage;

                Debug.Log("Flash!!");
            }).AddTo(_disposables);
        }
Exemplo n.º 26
0
 protected void ReactOn <TEvent>(Action <TEvent> handler)
 => _compositeDisposable.Add(_eventSystem.Receive <TEvent>().Subscribe(handler));
Exemplo n.º 27
0
        public void Setup(IEntity entity)
        {
            Debug.Log("Example Interactable System Setup");

            List <IDisposable> subscriptions = new List <IDisposable>();

            subscriptionsPerEntity.Add(entity, subscriptions);

            var baseInteractable    = entity.GetUnityComponent <IF_VR_Steam_Interactable>();
            var exampleInteractable = entity.GetComponent <IF_VR_Glove_SteamVRManus_Example_Interactable>();

            exampleInteractable.GeneralText.text  = "No Hand Hovering";
            exampleInteractable.HoveringText.text = "Hovering: False";

            var view = entity.GetGameObject();

            view.OnDestroyAsObservable().Subscribe(x =>
            {
                entityDatabase.RemoveEntity(entity);
            }).AddTo(subscriptions);

            eventSystem.Receive <IF_VR_Event_OnHandHoverBegin>().Subscribe(evt =>
            {
                if (evt.TargetEntity.Id == entity.Id)
                {
                    var handView = evt.HandEntity.GetGameObject();
                    exampleInteractable.GeneralText.text = "Hovering hand: " + handView.name;
                }
            }).AddTo(subscriptions);

            eventSystem.Receive <IF_VR_Event_OnHandHoverEnd>().Subscribe(evt =>
            {
                if (evt.TargetEntity.Id == entity.Id)
                {
                    exampleInteractable.GeneralText.text = "No Hand Hovering";
                }
            }).AddTo(subscriptions);

            eventSystem.Receive <IF_VR_Event_HandHoverUpdate>().Subscribe(evt =>
            {
                if (evt.TargetEntity.Id == entity.Id)
                {
                    var hand             = evt.HandEntity.GetUnityComponent <IF_VR_Steam_Hand>();
                    var startingGrabType = hand.GetGrabStarting();
                    bool isGrabEnding    = hand.IsGrabEnding(view);

                    if (baseInteractable.attachedToHand == null && startingGrabType != IF_VR_Steam_GrabTypes.None)
                    {
                        // Save our position/rotation so that we can restore it when we detach
                        exampleInteractable.oldPosition = view.transform.position;
                        exampleInteractable.oldRotation = view.transform.rotation;

                        // Call this to continue receiving HandHoverUpdate messages,
                        // and prevent the hand from hovering over anything else
                        hand.HoverLock(baseInteractable);

                        // Attach this object to the hand
                        hand.AttachObject(view, startingGrabType, exampleInteractable.AttachmentFlags);
                    }
                    else if (isGrabEnding)
                    {
                        // Detach this object from the hand
                        hand.DetachObject(view);

                        // Call this to undo HoverLock
                        hand.HoverUnlock(baseInteractable);

                        // Restore position/rotation
                        view.transform.position = exampleInteractable.oldPosition;
                        view.transform.rotation = exampleInteractable.oldRotation;
                    }
                }
            }).AddTo(subscriptions);

            eventSystem.Receive <IF_VR_Event_OnAttachedToHand>().Subscribe(evt =>
            {
                if (evt.TargetEntity.Id == entity.Id)
                {
                    var hand = evt.HandEntity.GetUnityComponent <IF_VR_Steam_Hand>();
                    exampleInteractable.GeneralText.text = string.Format("Attached: {0}", hand.name);
                    exampleInteractable.AttachTime       = Time.time;
                }
            }).AddTo(subscriptions);

            eventSystem.Receive <IF_VR_Event_OnDetachedToHand>().Subscribe(evt =>
            {
                if (evt.TargetEntity.Id == entity.Id)
                {
                    var hand = evt.HandEntity.GetUnityComponent <IF_VR_Steam_Hand>();
                    exampleInteractable.GeneralText.text = string.Format("Detached: {0}", hand.name);
                }
            }).AddTo(subscriptions);

            Observable.EveryUpdate()
            .Subscribe(x =>
            {
                if (baseInteractable.isHovering != exampleInteractable.LastHovering)
                {
                    exampleInteractable.HoveringText.text = string.Format("Hovering: {0}", baseInteractable.isHovering);
                    exampleInteractable.LastHovering      = baseInteractable.isHovering;
                }
            }).AddTo(subscriptions);
        }
 public CustomRefreshScheduler(IEventSystem eventSystem)
 {
     EventSystem          = eventSystem;
     DefaultRefreshPeriod = EventSystem.Receive <UnitEndTurnEvent>().Select(x => Unit.Default);
 }
Exemplo n.º 29
0
        public virtual void Initialize(IEventSystem eventSystem, IPoolManager poolManager)
        {
            EventSystem = eventSystem;
            EntityPool  = poolManager.GetPool();

            cachedEntities.ObserveAdd().Select(e => e.Value).Subscribe(entity =>
            {
                if (Predicates.Count == 0)
                {
                    PreAdd(entity);
                    AddEntity(entity);
                    return;
                }

                var bools = new List <ReactiveProperty <bool> >();
                for (int i = 0; i < Predicates.Count; i++)
                {
                    bools.Add(Predicates[i].Invoke(entity));
                }
                var onLatest            = Observable.CombineLatest(bools.ToArray());
                var predicateDisposable = onLatest.DistinctUntilChanged().Subscribe(values =>
                {
                    for (int i = 0; i < values.Count; i++)
                    {
                        if (!values[i])
                        {
                            if (Entities.Contains(entity))
                            {
                                PreRemove(entity);
                                RemoveEntity(entity);
                            }
                            return;
                        }
                    }
                    PreAdd(entity);
                    AddEntity(entity);
                }).AddTo(this.Disposer);
                predicatesTable.Add(entity, predicateDisposable);
            }).AddTo(this.Disposer);

            cachedEntities.ObserveRemove().Select(e => e.Value).Subscribe(entity =>
            {
                if (predicatesTable.ContainsKey(entity))
                {
                    predicatesTable[entity].Dispose();
                    predicatesTable.Remove(entity);
                }
                PreRemove(entity);
                RemoveEntity(entity);
            }).AddTo(this.Disposer);

            foreach (IEntity entity in EntityPool.Entities)
            {
                if (entity.HasComponents(Components))
                {
                    cachedEntities.Add(entity);
                }
            }

            EventSystem.Receive <EntityAddedEvent>().Subscribe(evt =>
            {
                if (!cachedEntities.Contains(evt.Entity) && evt.Entity.HasComponents(Components))
                {
                    cachedEntities.Add(evt.Entity);
                }
            }).AddTo(this);

            EventSystem.Receive <EntityRemovedEvent>().Subscribe(evt =>
            {
                if (cachedEntities.Contains(evt.Entity))
                {
                    cachedEntities.Remove(evt.Entity);
                }
            }).AddTo(this);

            EventSystem.Receive <ComponentsAddedEvent>().Subscribe(evt =>
            {
                if (!cachedEntities.Contains(evt.Entity) && evt.Entity.HasComponents(Components))
                {
                    cachedEntities.Add(evt.Entity);
                }
            }).AddTo(this);

            EventSystem.Receive <ComponentsRemovedEvent>().Subscribe(evt =>
            {
                if (cachedEntities.Contains(evt.Entity))
                {
                    foreach (var component in evt.Components)
                    {
                        for (int i = 0; i < Components.Length; i++)
                        {
                            if (Components[i] == component.GetType())
                            {
                                cachedEntities.Remove(evt.Entity);
                                return;
                            }
                        }
                    }
                }
            }).AddTo(this);
        }
Exemplo n.º 30
0
 public IObservable <IObservableGroup> ReactToGroup(IObservableGroup group)
 {
     return(_eventSystem.Receive <PlayerTurnEvent>().Select(x => group));
 }