feat(scripting): add runtime gameobject lifecycle api

This commit is contained in:
2026-03-27 16:30:16 +08:00
parent 26035e3940
commit a72f9f7f05
10 changed files with 395 additions and 0 deletions

View File

@@ -236,4 +236,34 @@ TEST_F(ScriptEngineTest, DestroyingGameObjectWhileRuntimeRunningDestroysTrackedS
EXPECT_EQ(engine->GetTrackedScriptCount(), 0u);
}
TEST_F(ScriptEngineTest, RuntimeCreatedScriptComponentIsTrackedImmediatelyAndStartsOnNextUpdate) {
Scene* runtimeScene = CreateScene("RuntimeScene");
engine->OnRuntimeStart(runtimeScene);
runtime.Clear();
GameObject* spawned = runtimeScene->CreateGameObject("Spawned");
ScriptComponent* component = AddScriptComponent(spawned, "Gameplay", "RuntimeSpawned");
EXPECT_EQ(engine->GetTrackedScriptCount(), 1u);
EXPECT_TRUE(engine->HasTrackedScriptComponent(component));
EXPECT_TRUE(engine->HasRuntimeInstance(component));
const std::vector<std::string> expectedBeforeUpdate = {
"Create:Spawned:Gameplay.RuntimeSpawned",
"Awake:Spawned:Gameplay.RuntimeSpawned",
"OnEnable:Spawned:Gameplay.RuntimeSpawned"
};
EXPECT_EQ(runtime.events, expectedBeforeUpdate);
runtime.Clear();
engine->OnUpdate(0.016f);
const std::vector<std::string> expectedAfterUpdate = {
"Start:Spawned:Gameplay.RuntimeSpawned",
"Update:Spawned:Gameplay.RuntimeSpawned"
};
EXPECT_EQ(runtime.events, expectedAfterUpdate);
}
} // namespace