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); } }
public void OnEntityComponentAdded(ComponentAddedEvent args) { var originalComponentTypes = args.Entity.Components.Select(x => x.GetType()).ToList(); originalComponentTypes.Remove(args.Component.GetType()); var previouslyMatched = ComponentTypes.All(x => originalComponentTypes.Contains(x)); if (previouslyMatched) { return; } var newComponentMatches = ComponentTypes.Contains(args.Component.GetType()); if (newComponentMatches) { OnEntityAdded.OnNext(args.Entity); } }