Files
XCEngine/engine/src/Components/Component.cpp

43 lines
912 B
C++
Raw Normal View History

#include <XCEngine/Components/Component.h>
#include <XCEngine/Components/GameObject.h>
namespace XCEngine {
namespace Components {
TransformComponent& Component::transform() const {
return *m_gameObject->GetTransform();
}
Scene* Component::GetScene() const {
return m_gameObject ? m_gameObject->GetScene() : nullptr;
}
void Component::SetEnabled(bool enabled) {
if (m_enabled == enabled) {
return;
}
bool wasEffectivelyEnabled = m_enabled;
bool isEffectivelyEnabled = enabled;
if (m_gameObject) {
wasEffectivelyEnabled = m_enabled && m_gameObject->IsActiveInHierarchy();
isEffectivelyEnabled = enabled && m_gameObject->IsActiveInHierarchy();
}
m_enabled = enabled;
if (wasEffectivelyEnabled == isEffectivelyEnabled) {
return;
}
if (isEffectivelyEnabled) {
OnEnable();
} else {
OnDisable();
}
}
}
}