Пример #1
0
        public void SetupSystem(ISystem system)
        {
            var processEntityFunction     = CreateEntityProcessorFunction(system);
            var entityChangeSubscriptions = new CompositeDisposable();

            SystemSubscriptions.Add(system, entityChangeSubscriptions);

            var entitySubscriptions = new Dictionary <int, IDisposable>();

            EntitySubscriptions.Add(system, entitySubscriptions);

            var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group);

            entityChangeSubscriptions.Add(
                observableGroup.EntityAdded.Subscribe(x =>
            {
                var subscription = processEntityFunction(x);
                entitySubscriptions.Add(x.Id, subscription);
            })
                );

            entityChangeSubscriptions.Add(
                observableGroup.EntityRemoved.Subscribe(x => entitySubscriptions.RemoveAndDispose(x.Id))
                );

            foreach (var entity in observableGroup)
            {
                var subscription = processEntityFunction(entity);
                entitySubscriptions.Add(entity.Id, subscription);
            }
        }
Пример #2
0
        public void SetupSystem(ISystem system)
        {
            var observableGroup           = EntityCollectionManager.GetObservableGroup(system.Group);
            var entitySubscriptions       = new Dictionary <int, IDisposable>();
            var entityChangeSubscriptions = new CompositeDisposable();

            SystemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem = (IReactToEntitySystem)system;

            entityChangeSubscriptions.Add(
                observableGroup.EntityAdded
                .Subscribe(entity =>
            {
                var entitySubscription = ProcessEntity(castSystem, entity);
                entitySubscriptions.Add(entity.Id, entitySubscription);
            })
                );

            entityChangeSubscriptions.Add(
                observableGroup.EntityRemoved
                .Subscribe(entity =>
            {
                entitySubscriptions.RemoveAndDispose(entity.Id);
            })
                );

            foreach (var entity in observableGroup)
            {
                var entitySubscription = ProcessEntity(castSystem, entity);
                entitySubscriptions.Add(entity.Id, entitySubscription);
            }

            EntitySubscriptions.Add(system, entitySubscriptions);
        }
Пример #3
0
        public void SubscribeToEntity(IEntity entity)
        {
            var disposer = new CompositeDisposable
            {
                entity.ComponentsAdded.Subscribe(ids =>
                                                 entityComponentsAdded.OnNext(new ComponentsChangedEvent(entity, this, ids))
                                                 ),
                entity.ComponentsRemoving.Subscribe(ids =>
                                                    entityComponentsRemoving.OnNext(new ComponentsChangedEvent(entity, this, ids))
                                                    ),
                entity.ComponentsRemoved.Subscribe(ids =>
                                                   entityComponentsRemoved.OnNext(new ComponentsChangedEvent(entity, this, ids))
                                                   )
            };

            EntitySubscriptions.Add(entity.Id, disposer);
        }
Пример #4
0
        public void SetupSystem(ISystem system)
        {
            var entitySubscriptions = new Dictionary <int, IDisposable>();

            EntitySubscriptions.Add(system, entitySubscriptions);

            var entityChangeSubscriptions = new CompositeDisposable();

            SystemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem      = (ISetupSystem)system;
            var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group);

            entityChangeSubscriptions.Add(
                observableGroup.EntityAdded.Subscribe(entity =>
            {
                var possibleSubscription = ProcessEntity(castSystem, entity);

                if (possibleSubscription != null)
                {
                    entitySubscriptions.Add(entity.Id, possibleSubscription);
                }
            })
                );

            entityChangeSubscriptions.Add(
                observableGroup.EntityRemoved
                .Subscribe(entity =>
            {
                if (entitySubscriptions.ContainsKey(entity.Id))
                {
                    entitySubscriptions.RemoveAndDispose(entity.Id);
                }
            })
                );

            foreach (var entity in observableGroup)
            {
                var possibleSubscription = ProcessEntity(castSystem, entity);

                if (null != possibleSubscription)
                {
                    entitySubscriptions.Add(entity.Id, possibleSubscription);
                }
            }
        }