public void AddComponent(IEntity entity, Type componenType) { ReactorConnection connection; if (!_connections.TryGetValue(componenType, out connection)) { var set = new HashSet <Type>(TargetTypes) { componenType }; SystemReactor reactor = _systemExecutor.GetSystemReactor(set); connection = new ReactorConnection(reactor, this); this.AddReactorsConnection(componenType, connection, reactor); } entity.Reactor = connection.UpReactor; _systemExecutor.AddSystemsToEntity(entity, connection); }
//todo: строить без использования финального реактора, а использовать постепенное построение, что бы избежать необходимость установки очередности с помощью приоритетов public IEntity CreateEntity <T>(T blueprint, Action <IEntity> preSetup = null) where T : class, IBlueprint { var type = typeof(T); var components = blueprint.Build().ToList(); SystemReactor reactor; if (!_reactorIndex.TryGetValue(type, out reactor)) { var hs = new HashSet <Type>(); foreach (var component in components) { hs.Add(component.GetType()); } // todo: находит реактор, у которого индекс не совпадает с сущностью reactor = _executor.GetSystemReactor(hs); _reactorIndex.Add(type, reactor); } var sortedComponents = new IComponent[components.Count]; foreach (var component in components) { sortedComponents[reactor.GetComponentIdx(component.TypeId)] = component; } var entity = EntityFactory.Create(this, _indexPool.GetId(), sortedComponents, reactor); _entities.Add(entity); if (preSetup != null) { preSetup(entity); } reactor.AddEntityToReactor(entity); EventSystem.Publish(new EntityAddedEvent(entity, this)); return(entity); }