feat(ecs): per-component enable/disable + inspector rework
Add `active` flag to the 8 behavior components (Unity enabled / UE SetActive semantics; structural Id/Name/Transform excluded). Consumers skip disabled components: renderer (mesh/light/anim), primary camera election, physics reconciliation (body/constraint/character destroyed and rebuilt on toggle), scripts keep instance but stop ticking. Inspector: component headers now carry an enable checkbox and a remove button, Add-Component menu greys out attached entries, and conflict hints added (RigidBody <-> CharacterController mutual exclusion, Joint requires RigidBody, Animation requires MeshRenderer, unregistered script name). Scenes persist Active per component (default true).
This commit is contained in:
@@ -22,9 +22,14 @@ namespace Engine {
|
||||
auto& reg = m_Scene.GetRegistry();
|
||||
for (auto& [bits, inst] : m_Instances) {
|
||||
const auto e = static_cast<entt::entity>(bits);
|
||||
if (!reg.valid(e) || !reg.any_of<ECS::ScriptComponent>(e)) {
|
||||
const ECS::ScriptComponent* sc = reg.valid(e)
|
||||
? reg.try_get<ECS::ScriptComponent>(e) : nullptr;
|
||||
if (!sc) {
|
||||
continue; // 延迟销毁队列里,下帧 Sync 清理
|
||||
}
|
||||
if (!sc->active) {
|
||||
continue; // 禁用 = 保留实例停 tick(Unity disable 语义)
|
||||
}
|
||||
if (!inst.created) {
|
||||
inst.behavior->OnCreate();
|
||||
inst.created = true;
|
||||
|
||||
Reference in New Issue
Block a user