示例#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 TeardownSystem(ISystem system)
        {
            SystemSubscriptions.RemoveAndDispose(system);

            var entitySubscriptions = EntitySubscriptions[system];

            entitySubscriptions.Values.DisposeAll();
            entitySubscriptions.Clear();

            EntitySubscriptions.Remove(system);
        }
示例#4
0
        public void Dispose()
        {
            SystemSubscriptions.DisposeAll();

            foreach (var entitySubscriptions in EntitySubscriptions.Values)
            {
                entitySubscriptions.Values.DisposeAll();
                entitySubscriptions.Clear();
            }

            EntitySubscriptions.Clear();
        }