Beispiel #1
0
        protected ICommand BindToEvent <TEvent>(Func <IListManager, TEvent?> exec, Func <IListManager, bool>?canExec = null, Action?postExec = null)
            where TEvent : class
        {
            var manager = _listManager;

            // ReSharper disable once ImplicitlyCapturedClosure
            async void Exec(object arg) =>
            await Task.Run(() =>
            {
                var e = exec(manager);
                if (e == null)
                {
                    return;
                }

                _eventSystem.Publish(e);

                postExec?.Invoke();
            });

            // ReSharper disable once ImplicitlyCapturedClosure
            bool CanExec(object arg) => canExec == null || canExec(manager);

            return(new DelegateCommand(Exec, CanExec));
        }
        private async Task MessageQueueOnWork(OperationComponent arg)
        {
            _eventSystem.Publish(new OperationStartedEvent(arg.OpsId));
            await arg.Task(arg.Data);

            _operations.Remove(arg);
            _eventSystem.Publish(new OperationFinishtEvent(arg.OpsId));
        }
Beispiel #3
0
        private void _restartLevel()
        {
            var levelEvent = new LevelEvent()
            {
                action = LevelActions.RESTART
            };

            _eventSystem.Publish(levelEvent);
        }
Beispiel #4
0
        private void _stopLevel()
        {
            var levelEvent = new LevelEvent()
            {
                action = LevelActions.STOP
            };

            _eventSystem.Publish(levelEvent);
            _pool.RemoveAllEntities();
        }
 public static void Send <T>(this IEventSystem eventSystem, T message)
 {
     if (typeof(T) == typeof(object) || typeof(ISerializableEvent).IsAssignableFrom(typeof(T)))
     {
         eventSystem.Publish((object)message);
     }
     else
     {
         eventSystem.Publish(message);
     }
 }
 public void OnHandHoverBegin(GameObject sourceGo, GameObject argGo)
 {
     eventSystem.Publish(new IF_VR_Event_OnHandHoverBegin()
     {
         TargetEntity = sourceGo.GetEntity(),
         HandEntity   = argGo.GetEntity()
     });
 }
Beispiel #7
0
        private void _publishKill(Collision2D collision, IEntity entity)
        {
            var entityView   = collision.gameObject.GetComponent <EntityView>();
            var sourceEntity = entityView.Entity;
            var killEvent    = new KillEvent()
            {
                source = sourceEntity,
                target = entity
            };

            _eventSystem.Publish(killEvent);
        }
Beispiel #8
0
        private void ProcessInput()
        {
            if (Input.GetKey(KeyCode.Space))
            {
                _eventSystem.Publish(new ShootBulletEvent());
            }

            if (Input.GetKeyDown(KeyCode.Backspace))
            {
                _eventSystem.Publish(new DespawnAllBulletsEvent());
            }
        }
        public void Execute(IEntity entity)
        {
            var view = entity.GetComponent <ViewComponent>().View;
            var movementComponent = entity.GetComponent <MovementComponent>();

            Vector2 currentPosition = view.transform.position;
            var     destination     = currentPosition + movementComponent.Movement.Value;
            var     collidedObject  = CheckForCollision(view, currentPosition, destination);
            var     canMove         = collidedObject == null;

            var isPlayer = entity.HasComponent <PlayerComponent>();

            if (!canMove)
            {
                movementComponent.Movement.Value = Vector2.zero;

                var entityView = collidedObject.GetComponent <EntityView>();
                if (!entityView)
                {
                    return;
                }

                if (isPlayer && collidedObject.tag.Contains("Wall"))
                {
                    WallHit(entityView.Entity, entity);
                }

                if (isPlayer && collidedObject.tag.Contains("Enemy"))
                {
                    EnemyHit(entityView.Entity, entity);
                }

                if (!isPlayer && collidedObject.tag.Contains("Player"))
                {
                    PlayerHit(entityView.Entity, entity);
                }

                return;
            }

            var rigidBody = view.GetComponent <Rigidbody2D>();

            MainThreadDispatcher.StartUpdateMicroCoroutine(SmoothMovement(view, rigidBody, destination, movementComponent));
            _eventSystem.Publish(new EntityMovedEvent(isPlayer));

            if (isPlayer)
            {
                var playerComponent = entity.GetComponent <PlayerComponent>();
                playerComponent.Food.Value--;
            }
        }
Beispiel #10
0
        IEnumerator loadContentCO(IObserver <Unit> observer, ContentType type)
        {
            eventSystem.Publish(new ContentLoadEvent()
            {
            });

            yield return(ensureLoadBaseCO());

            // give some frametime
            yield return(new WaitForEndOfFrame());

            // unload modules
            yield return(unloadContentCO());

            // give some frametime
            yield return(new WaitForEndOfFrame());

            // load plugin
            loadContentPlugin(type);

            // give some frametime
            yield return(new WaitForEndOfFrame());

            // load target content scene
            string contentSceneName = type.ToString();
            var    op = SceneManager.LoadSceneAsync(contentSceneName, LoadSceneMode.Additive);

            while (!op.isDone)
            {
                yield return(null);
            }

            // check ensure loaded
            var contentScene = SceneManager.GetSceneByName(contentSceneName);

            while (!contentScene.isLoaded)
            {
                yield return(null);
            }

            // give some frametime
            yield return(new WaitForEndOfFrame());

            eventSystem.Publish(new ContentLoadedEvent()
            {
            });

            observer.OnNext(Unit.Default);
            observer.OnCompleted();
        }
 public virtual void Initialize(IEventSystem eventSystem)
 {
     EventSystem = eventSystem;
     EventSystem.Publish(new ComponentCreated()
     {
         Component = this
     });
 }
Beispiel #12
0
        public IEntity CreateUI(IEntity ui)
        {
            var uiComponent = ui.GetComponent <UIComponet>();

            if (uiComponent.UIType == UIType.UI_ADD_SCREEN)
            {
                if (CurrentScreen.Value != null)
                {
                    RemoveUI(CurrentScreen.Value);
                }
                CurrentScreen.Value = ui;
            }

            //var viewComponent = ui.GetComponent<ViewComponent>();
            //viewComponent.View.SetActive(true);
            eventSystem.Publish(new UIShowedEvent(ui));
            return(ui);
        }
Beispiel #13
0
        private void _publishKill(IEntity source, IEntity target)
        {
            var killEvent = new KillEvent()
            {
                source = source,
                target = target
            };

            _eventSystem.Publish(killEvent);
        }
        private IEnumerator CarryOutTurns(IObservableGroup group)
        {
            _isProcessing = true;
            yield return(new WaitForSeconds(_gameConfiguration.TurnDelay));

            if (!group.Any())
            {
                yield return(new WaitForSeconds(_gameConfiguration.TurnDelay));
            }

            foreach (var enemy in group)
            {
                _eventSystem.Publish(new EnemyTurnEvent(enemy));
                yield return(new WaitForSeconds(_gameConfiguration.MovementTime));
            }

            _eventSystem.Publish(new PlayerTurnEvent());

            _isProcessing = false;
        }
        private void _publish(Collider2D collider, IEntity entity)
        {
            var entityView   = collider.gameObject.GetComponent <EntityView>();
            var sourceEntity = entityView.Entity;
            var scoreEvent   = new ScoreEvent()
            {
                source = sourceEntity,
                target = entity
            };

            _eventSystem.Publish(scoreEvent);
        }
        private IEnumerator CarryOutTurns(IGroupAccessor @group)
        {
            _isProcessing = true;
            yield return(new WaitForSeconds(_gameConfiguration.TurnDelay));

            if ([email protected]())
            {
                yield return(new WaitForSeconds(_gameConfiguration.TurnDelay));
            }

            var enemies = @group.Entities;

            foreach (var enemy in enemies)
            {
                _eventSystem.Publish(new EnemyTurnEvent(enemy));
                yield return(new WaitForSeconds(_gameConfiguration.MovementTime));
            }

            _eventSystem.Publish(new PlayerTurnEvent());

            _isProcessing = false;
        }
Beispiel #17
0
        public void Process(IEntity entity, TimeSpan value)
        {
            var game     = entity.GetComponent <GameComponent>();
            var newValue = countdown - value;

            if (TimeSpan.Zero < newValue)
            {
                countdown = newValue;

                if (warningTimeout >= countdown)
                {
                    eventSystem.Publish(new NewEnemyWaveIncomingEvent(game, countdown));
                }

                return;
            }

            LastWaveTime.Value = game.Elapsed.Value;
            countdown          = Timeout;

            eventSystem.Publish(new NewEnemyWaveEvent(game, waveNumber++, LastWaveTime.Value));
        }
Beispiel #18
0
 public void OnParentHandHoverBegin(GameObject sourceGo, GameObject argGo)
 {
     eventSystem.Publish(new IF_VR_EventOnParentHandHoverBegin()
     {
         SourceEntity       = sourceGo.GetEntity(),
         InteractableEntity = argGo.GetEntity()
     });
 }
        public void Process(PlayerHitEvent eventData)
        {
            var enemyComponent  = eventData.Enemy.GetComponent <EnemyComponent>();
            var playerComponent = eventData.Player.GetComponent <PlayerComponent>();

            playerComponent.Food.Value -= enemyComponent.EnemyPower;

            var animator = eventData.Enemy.GetUnityComponent <Animator>();

            animator.SetTrigger("enemyAttack");

            if (playerComponent.Food.Value <= 0)
            {
                _eventSystem.Publish(new PlayerKilledEvent(eventData.Player));
            }
        }
Beispiel #20
0
        /// <inheritdoc />
        public void Setup(IEntity entity)
        {
            var inputComponent   = entity.GetComponent <InputComponent>();
            var movableComponent = entity.GetComponent <MovableComponent>();
            var damageComponent  = entity.GetComponent <DamageComponent>();

            inputComponent.Movement.Subscribe(x => movableComponent.Movement.Value = x).AddTo(_disposables);
            inputComponent.Attack.ThrottleFirst(TimeSpan.FromMilliseconds(damageComponent.Throttle)).Subscribe(__ => _eventSystem.Publish(new AttackEvent(entity, damageComponent.Damage))).AddTo(_disposables);

            var gameObject = entity.GetGameObject();
            var onTriggerEnter2DAsObservable = gameObject.OnTriggerEnter2DAsObservable();

            onTriggerEnter2DAsObservable.Where(x => x.GetComponent <EntityView>().Entity.HasComponent <PickupableComponent>())
            .Subscribe(x => _eventSystem.Publish(new PickupEvent(entity, x.GetComponent <EntityView>().Entity)))
            .AddTo(_disposables);
        }
Beispiel #21
0
        public void LoadFrom(string path, ISourceList <DataComponent> to)
        {
            _lastCollection = to;
            _last           = path;

            var targetPath = GetFullPath(path);

            if (!File.Exists(targetPath))
            {
                return;
            }

            try
            {
                JObject obj;

                try
                {
                    obj = JObject.Parse(File.ReadAllText(targetPath));
                }
                catch
                {
                    obj = JObject.Parse(File.ReadAllText(targetPath + 1));
                }

                to.AddRange(from property in obj.Properties()
                            let blue = _blueprintDescriptors.FirstOrDefault(bd => bd.Category == property.Name)
                                       ?? _blueprintDescriptors.First(bd => bd.Category == "general")
                                       let jValue = (JArray)property.Value
                                                    from entry in jValue
                                                    select blue.Create(entry.Value <string>("Category"), entry.Value <string>("Value")));
            }
            catch
            {
                try
                {
                    File.Delete(targetPath);
                }
                catch (IOException)
                {
                }
            }
            finally
            {
                _eventSystem.Publish(new DataLoadedEvent());
            }
        }
        private void _publish(IEntity entity, Collider2D collider)
        {
            var targetEntity = _getEntity(entity, collider);

            if (targetEntity == null)
            {
                return;
            }

            var damageEvent = new DamageEvent()
            {
                source = entity,
                target = targetEntity
            };

            _eventSystem.Publish(damageEvent);
        }
Beispiel #23
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);
        }
Beispiel #24
0
 private void HandleFoodPickup(IEntity food, IEntity player, bool isSoda)
 {
     _eventSystem.Publish(new FoodPickupEvent(food, player, isSoda));
 }