Files
XCEngine/docs/api/XCEngine/Scene/SceneRuntime/Start.md

43 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SceneRuntime::Start
**命名空间**: `XCEngine::Components`
**类型**: `method`
**头文件**: `XCEngine/Scene/SceneRuntime.h`
## 签名
```cpp
void Start(Scene* scene);
```
## 作用
让一个场景进入运行状态,并启动其脚本运行时。
## 当前实现流程
`engine/src/Scene/SceneRuntime.cpp`
1. 如果当前已经在运行同一个 `scene`,直接返回。
2. 先调用 [Stop](Stop.md) 清掉旧运行时。
3. 如果传入空场景,返回。
4. 写入 `m_scene`,把 `m_running` 设为 `true`
5. 调用 `ScriptEngine::Get().OnRuntimeStart(scene)`
## 参数
| 参数 | 说明 |
|------|------|
| `scene` | 要开始运行的场景;可为空,空时表示“停掉当前运行时但不启动新场景”。 |
## 设计含义
这种“先停再启”的切换方式很直接,也和很多商业引擎的 play mode 切场景行为一致。优点是生命周期边界清晰;代价是当前没有做平滑切换或状态迁移。
## 相关文档
- [SceneRuntime](SceneRuntime.md)
- [SceneRuntime::Stop](Stop.md)