Beispiel #1
0
        public IEntity CreateEntity()
        {
            var components = new List <IComponent>();

            SystemReactor reactor = _executor.GetSystemReactor(components);

            var entity = EntityFactory.Create(this, _indexPool.GetId(), components, reactor);

            _entities.Add(entity);

            reactor.AddEntityToReactor(entity);

            EventSystem.Publish(new EntityAddedEvent(entity, this));

            return(entity);
        }
Beispiel #2
0
        public IEntity CreateEntity(IEnumerable <IComponent> components)
        {
            SystemReactor reactor = _executor.GetSystemReactor(components);

            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);

            reactor.AddEntityToReactor(entity);

            EventSystem.Publish(new EntityAddedEvent(entity, this));

            return(entity);
        }