예제 #1
0
//-------------------------------------------------------------
//-------------------------------------------------------------
void Entity::AddComponent(const ComponentSPtr& in_component)
{
    CS_ASSERT(in_component != nullptr, "Cannot add null component");
    CS_ASSERT(in_component->GetEntity() == nullptr, "Component cannot be attached to more than 1 entity at a time.");
    CS_ASSERT(m_components.size() < static_cast<std::vector<ComponentSPtr>::size_type>(std::numeric_limits<u32>::max()), "There are too many components. It cannot exceed "
              + CSCore::ToString(std::numeric_limits<u32>::max()) + ".");

    m_components.push_back(in_component);

    in_component->SetEntity(this);

    in_component->OnAddedToEntity();

    if(GetScene() != nullptr)
    {
        in_component->OnAddedToScene();
        if (m_appActive == true)
        {
            in_component->OnResume();
            if (m_appForegrounded == true)
            {
                in_component->OnForeground();
            }
        }
    }
}
예제 #2
0
        //-------------------------------------------------------------
		//-------------------------------------------------------------
		void Entity::AddComponent(const ComponentSPtr& in_component)
		{
            CS_ASSERT(in_component != nullptr, "Cannot add null component");
            CS_ASSERT(in_component->GetEntity() == nullptr, "Component cannot be attached to more than 1 entity at a time.");
            
            m_components.push_back(in_component);
            
            in_component->SetEntity(this);
            
            in_component->OnAddedToEntity();
            
            if(GetScene() != nullptr)
            {
                in_component->OnAddedToScene();
                if (m_appActive == true)
                {
                    in_component->OnResume();
                    if (m_appForegrounded == true)
                    {
                        in_component->OnForeground();
                    }
                }
            }
		}