Fix play mode runtime scene replacement
This commit is contained in:
@@ -141,6 +141,54 @@ void ScriptEngine::OnRuntimeStop() {
|
||||
m_runtime->OnRuntimeStop(stoppedScene);
|
||||
}
|
||||
|
||||
void ScriptEngine::OnRuntimeSceneReplaced(Components::Scene* scene) {
|
||||
if (!m_runtimeRunning) {
|
||||
m_runtimeScene = nullptr;
|
||||
m_runtimeSceneCreatedSubscription = 0;
|
||||
m_scriptStates.clear();
|
||||
m_scriptOrder.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
const float configuredFixedDeltaTime = m_runtimeFixedDeltaTime;
|
||||
m_runtime->OnRuntimeStop(nullptr);
|
||||
m_runtimeFixedDeltaTime = configuredFixedDeltaTime;
|
||||
|
||||
m_runtimeScene = scene;
|
||||
m_runtimeSceneCreatedSubscription = 0;
|
||||
m_scriptStates.clear();
|
||||
m_scriptOrder.clear();
|
||||
|
||||
if (!m_runtimeScene) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_runtime->OnRuntimeStart(m_runtimeScene);
|
||||
m_runtimeSceneCreatedSubscription = m_runtimeScene->OnGameObjectCreated().Subscribe(
|
||||
[this](Components::GameObject* gameObject) {
|
||||
HandleGameObjectCreated(gameObject);
|
||||
});
|
||||
|
||||
for (Components::GameObject* root : m_runtimeScene->GetRootGameObjects()) {
|
||||
CollectScriptComponents(root);
|
||||
}
|
||||
|
||||
const std::vector<ScriptInstanceKey> startupKeys = m_scriptOrder;
|
||||
for (const ScriptInstanceKey& key : startupKeys) {
|
||||
auto it = m_scriptStates.find(key);
|
||||
if (it == m_scriptStates.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScriptInstanceState& state = it->second;
|
||||
if (!ShouldScriptRun(state)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EnsureScriptReady(state, true);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::OnFixedUpdate(float fixedDeltaTime) {
|
||||
if (!m_runtimeRunning) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user