void Entity::AddComponent(const Foundation::ComponentInterfacePtr &component) { // Must exist and be free if (component && component->GetParentEntity() == 0) { component->SetParentEntity(this); components_.push_back(component); ///\todo Ali: send event } }
void Entity::AddComponent(const Foundation::ComponentInterfacePtr &component, AttributeChange::Type change) { // Must exist and be free if (component && component->GetParentEntity() == 0) { component->SetParentEntity(this); components_.push_back(component); if (scene_) scene_->EmitComponentAdded(this, component.get(), change); } }
void Entity::RemoveComponent(const Foundation::ComponentInterfacePtr &component) { if (component) { ComponentVector::iterator iter = std::find(components_.begin(), components_.end(), component); if (iter != components_.end()) { (*iter)->SetParentEntity(0); components_.erase(iter); ///\todo Ali: send event } else { Foundation::RootLogWarning("Failed to remove component: " + component->Name() + " from entity: " + ToString(GetId())); } } }
void Entity::RemoveComponent(const Foundation::ComponentInterfacePtr &component, AttributeChange::Type change) { if (component) { ComponentVector::iterator iter = std::find(components_.begin(), components_.end(), component); if (iter != components_.end()) { if (scene_) scene_->EmitComponentRemoved(this, (*iter).get(), change); (*iter)->SetParentEntity(0); components_.erase(iter); } else { LogWarning("Failed to remove component: " + component->TypeName().toStdString() + " from entity: " + ToString(GetId())); } } }