Files
XCEngine/docs/api/XCEngine/Scene/SceneManager/UnloadScene.md

1.2 KiB

SceneManager::UnloadScene

卸载一个已登记场景。

void UnloadScene(Scene* scene);
void UnloadScene(const std::string& sceneName);

行为说明

当前有两个重载:

  • 指针重载:
    1. scene == nullptr 时直接返回。
    2. 如果它正好是 m_activeScene,先把活动场景清空。
    3. m_scenes 里线性查找匹配指针。
    4. 找到后触发 OnSceneUnloaded,然后擦除。
    5. 如果活动场景为空且仍有剩余场景,选择 m_scenes.begin() 作为新的活动场景,并触发 OnActiveSceneChanged
  • 字符串重载:先按 key 查找,再转到指针重载。

参数

  • scene - 待卸载场景指针。
  • sceneName - 待卸载场景 key。

返回值

  • 无。

当前实现限制

  • 后备活动场景来自 unordered_map 首元素,选择顺序不稳定。
  • 如果卸载的是最后一个活动场景,当前不会额外发出“活动场景变为 nullptr”的切换事件。
  • 指针重载内部需要线性扫描 map 找到匹配场景。

相关文档