update ComponentManager

This commit is contained in:
Nomango 2020-06-21 19:05:46 +08:00
parent 0f3b5ca473
commit b90642fd15
2 changed files with 19 additions and 2 deletions

View File

@ -33,12 +33,23 @@ Component* ComponentManager::AddComponent(ComponentPtr component)
{
KGE_ASSERT(component && "AddComponent failed, NULL pointer exception");
if (component)
{
size_t hash = std::hash<String>{}(component->GetName());
AddComponent(hash, component);
}
return component.Get();
}
Component* ComponentManager::AddComponent(size_t index, ComponentPtr component)
{
KGE_ASSERT(component && "AddComponent failed, NULL pointer exception");
if (component)
{
component->InitComponent(target_);
size_t hash = std::hash<String>{}(component->GetName());
components_.insert(std::make_pair(hash, component));
components_.insert(std::make_pair(index, component));
}
return component.Get();
}

View File

@ -46,6 +46,12 @@ public:
/// @param component 组件
Component* AddComponent(ComponentPtr component);
/// \~chinese
/// @brief 添加组件
/// @param index 索引值
/// @param component 组件
Component* AddComponent(size_t index, ComponentPtr component);
/// \~chinese
/// @brief 获取组件
Component* GetComponent(const String& name);