feat(scripting): add runtime gameobject lifecycle api
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user