2026-03-25 12:30:05 +08:00
|
|
|
#include <XCEngine/Components/Component.h>
|
|
|
|
|
#include <XCEngine/Components/GameObject.h>
|
|
|
|
|
|
|
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace Components {
|
|
|
|
|
|
|
|
|
|
TransformComponent& Component::transform() const {
|
|
|
|
|
return *m_gameObject->GetTransform();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 20:14:58 +08:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2026-03-25 12:30:05 +08:00
|
|
|
}
|