public void OnEntityComponentRemoved(ComponentRemovedEvent args) { var originalComponents = args.Entity.Components.ToList(); originalComponents.Add(args.Component); var applicableSystems = _systems.GetApplicableSystems(originalComponents); var effectedSystems = applicableSystems.Where(x => x.TargetGroup.TargettedComponents.Contains(args.Component.GetType())); foreach (var effectedSystem in effectedSystems) { if (effectedSystem.TargetGroup.CanProcessEntity(args.Entity)) { if (effectedSystem is ITeardownSystem) { (effectedSystem as ITeardownSystem).Teardown(args.Entity); } var subscriptionTokens = _systemSubscriptions[effectedSystem] .Where(x => x.AssociatedObject == args.Entity) .ToList(); _systemSubscriptions[effectedSystem].RemoveAllFrom(subscriptionTokens); subscriptionTokens.DisposeAll(); } } }
public void OnEntityComponentRemoved(ComponentRemovedEvent args) { if (!args.Entity.HasComponents(AccessorToken.ComponentTypes)) { CachedEntities.Remove(args.Entity); } }
private void HandleShipComponentRemovedEvent(ComponentRemovedEvent <PlayerShipComponent> shipComponentRemovedEvent) { foreach (Entity shield in shipComponentRemovedEvent.Component.ShipShields) { Engine.DestroyEntity(shield); } }
public void RemoveComponent(EntityComponent entityComponent) { if (_components.Remove(entityComponent)) { ComponentRemovedEvent?.Invoke(this, entityComponent); entityComponent.Deinitialize(); } }
public void OnEntityComponentRemoved(ComponentRemovedEvent args) { var originalComponents = args.Entity.Components.ToList(); originalComponents.Add(args.Component); var applicableSystems = _systems.GetApplicableSystems(originalComponents).ToArray(); var effectedSystems = applicableSystems.Where(x => x.TargetGroup.TargettedComponents.Contains(args.Component.GetType())); effectedSystems.ForEachRun(system => _systemSubscriptions[system].Where(subscription => subscription.AssociatedObject == args.Entity)); }
public void OnEntityComponentRemoved(ComponentRemovedEvent args) { var originalComponents = args.Entity.Components.Select(x => x.GetType()).ToList(); originalComponents.Add(args.Component.GetType()); var matchesGroup = originalComponents.All(x => ComponentTypes.Contains(x)); if (matchesGroup) { OnEntityRemoved.OnNext(args.Entity); } }
void HandleComponentRemoved(ComponentRemovedEvent e) { Component component; try { // will throw if component isn't a known native component = e.Component; } catch { return; } if (component.GetType() == typeof(PhysicsWorld) || component.GetType() == typeof(PhysicsWorld2D)) { UnsubscribeFromEvent <PhysicsPreStepEvent>(); UnsubscribeFromEvent <PhysicsPostStepEvent>(); } if (component.GetType().GetTypeInfo().IsSubclassOf(typeof(CSComponent))) { var csc = (CSComponent)component; CSComponentInfo info; if (!CSComponentCore.csinfoLookup.TryGetValue(csc.GetType(), out info)) { return; } cscomponentStart.Remove(csc); List <CSComponent> cslist; if (!cscomponents.TryGetValue(info, out cslist)) { return; } cslist.Remove(csc); } }
public override bool Handle(IEvent evt) { ComponentRemovedEvent <PlayerShipComponent> playerShipCompRemovedEvent = evt as ComponentRemovedEvent <PlayerShipComponent>; if (playerShipCompRemovedEvent != null) { for (int i = 0; i < _superShieldDisplayEntities.Count; i++) { Entity superShieldDisplayEntity = _superShieldDisplayEntities[i]; SuperShieldComponent superShieldComp = superShieldDisplayEntity.GetComponent <SuperShieldComponent>(); if (superShieldComp.ship == playerShipCompRemovedEvent.Entity) { Engine.DestroyEntity(superShieldDisplayEntity); i--; } } } return(false); }
public void should_only_remove_entity_when_components_no_longer_match_group() { var mockEventSystem = Substitute.For <IEventSystem>(); var accessorToken = new GroupAccessorToken(new[] { typeof(TestComponentOne), typeof(TestComponentTwo) }, "default"); var mockPool = Substitute.For <IPool>(); var existingEntityOne = new Entity(Guid.NewGuid(), mockPool, mockEventSystem); var componentToRemove = new TestComponentOne(); existingEntityOne.AddComponent(componentToRemove); existingEntityOne.AddComponent <TestComponentTwo>(); var existingEntityTwo = new Entity(Guid.NewGuid(), mockPool, mockEventSystem); var unapplicableComponent = new TestComponentThree(); existingEntityTwo.AddComponent <TestComponentOne>(); existingEntityTwo.AddComponent <TestComponentTwo>(); existingEntityTwo.AddComponent(unapplicableComponent); var dummyEventToSeedMock = new ComponentRemovedEvent(new Entity(Guid.NewGuid(), mockPool, mockEventSystem), new TestComponentOne()); var underlyingEvent = new ReactiveProperty <ComponentRemovedEvent>(dummyEventToSeedMock); mockEventSystem.Receive <ComponentRemovedEvent>().Returns(underlyingEvent); var cacheableGroupAccessor = new CacheableGroupAccessor(accessorToken, new IEntity[] { existingEntityOne, existingEntityTwo }, mockEventSystem); cacheableGroupAccessor.MonitorEntityChanges(); existingEntityOne.RemoveComponent(componentToRemove); underlyingEvent.SetValueAndForceNotify(new ComponentRemovedEvent(existingEntityOne, componentToRemove)); existingEntityTwo.RemoveComponent(unapplicableComponent); underlyingEvent.SetValueAndForceNotify(new ComponentRemovedEvent(existingEntityTwo, unapplicableComponent)); Assert.That(cacheableGroupAccessor.CachedEntities, Has.Count.EqualTo(1)); Assert.That(cacheableGroupAccessor.CachedEntities, Contains.Item(existingEntityTwo)); }
public override bool Handle(IEvent evt) { ComponentRemovedEvent <LaserBeamComponent> laserBeamComponentRemovedEvent = evt as ComponentRemovedEvent <LaserBeamComponent>; if (laserBeamComponentRemovedEvent != null) { LaserBeamComponent laserBeamComp = laserBeamComponentRemovedEvent.Component; // Laser beam destruction Entity reflectionBeamEntity = laserBeamComp.ReflectionBeamEntity; while (reflectionBeamEntity != null) { Entity entityToDestroy = reflectionBeamEntity; LaserBeamComponent reflectionBeamComp = entityToDestroy.GetComponent <LaserBeamComponent>(); if (reflectionBeamComp != null) { reflectionBeamEntity = reflectionBeamComp.ReflectionBeamEntity; } Engine.DestroyEntity(entityToDestroy); } } ComponentRemovedEvent <LaserEnemyComponent> laserEnemyComponentRemovedEvent = evt as ComponentRemovedEvent <LaserEnemyComponent>; if (laserEnemyComponentRemovedEvent != null) { LaserEnemyComponent laserEnemyComp = laserEnemyComponentRemovedEvent.Component; if (laserEnemyComp.LaserBeamEntity != null) { Engine.DestroyEntity(laserEnemyComp.LaserBeamEntity); } } return(false); }
public void OnEntityComponentRemoved(ComponentRemovedEvent args) { args.Entity.Reactor.RemoveComponent(args.Entity, args.Component.GetType()); }
void HandleComponentRemoved(ComponentRemovedEvent e) { Component component; try { // will throw if component isn't a known native component = e.Component; } catch { return; } if (component.GetType() == typeof(PhysicsWorld) || component.GetType() == typeof(PhysicsWorld2D)) { UnsubscribeFromEvent<PhysicsPreStepEvent>(); UnsubscribeFromEvent<PhysicsPostStepEvent>(); } if (component.GetType().GetTypeInfo().IsSubclassOf(typeof(CSComponent))) { var csc = (CSComponent)component; CSComponentInfo info; if (!CSComponentCore.csinfoLookup.TryGetValue(csc.GetType(), out info)) { return; } cscomponentStart.Remove(csc); List<CSComponent> cslist; if (!cscomponents.TryGetValue(info, out cslist)) { return; } cslist.Remove(csc); } }