public void SetComponents <TComponentValue>(TEntityId entityId, IEnumerable <TComponentKind> componentKinds, Converter <TComponentKind, TComponentValue> componentSelector) { var componentKindList = EnumerableHelper.AsIList(componentKinds); if (BufferSetComponents(entityId, componentKindList, componentSelector)) { return; } var entityComponentStorage = _componentsByEntity[entityId]; var addedComponentKinds = new List <TComponentKind>(); foreach (var componentKind in componentKindList) { if ( entityComponentStorage.Set ( componentKind, key => _componentKindRegistry.GetOrCreateTypedContainer <TComponentValue>(key).Add(componentSelector(key)), pair => _componentKindRegistry.GetOrCreateTypedContainer <TComponentValue>(pair.Key).Update(pair.Value, componentSelector(pair.Key)) ) ) { addedComponentKinds.Add(componentKind); } } if (addedComponentKinds.Count > 0) { _entityComponentEventDispatcher.NotifyAddedComponents(entityId, addedComponentKinds); } }