docs: Add Component, GameObject, TransformComponent and Scene API documentation

- Add Component class documentation with lifecycle methods
- Add GameObject class documentation with component system
- Add TransformComponent documentation with transform methods
- Add Scene class documentation with GameObject management
- Add SceneManager singleton documentation with scene loading
- Update components.md overview with all component classes
- Update main.md navigation with Scene module
This commit is contained in:
2026-03-22 03:33:55 +08:00
parent d83ed56177
commit a9d5a68dd6
105 changed files with 3003 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
# CreateScene
Create a new scene with the specified name.
## Syntax
```cpp
Scene* CreateScene(const std::string& name);
```
## Parameters
- `name` - The name for the new scene.
## Returns
Returns a pointer to the newly created `Scene`.
## See Also
- [LoadScene](load-scene)
- [UnloadScene](unload-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
Scene* newScene = manager.CreateScene("Level1");
}
```

View File

@@ -0,0 +1,29 @@
# GetActiveScene
Get the currently active scene.
## Syntax
```cpp
Scene* GetActiveScene() const;
```
## Returns
Returns a pointer to the currently active `Scene`, or `nullptr` if no scene is active.
## See Also
- [SetActiveScene](set-active-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
Scene* active = manager.GetActiveScene();
if (active) {
XC_LOG_INFO("Active scene: {}", active->GetName());
}
}
```

View File

@@ -0,0 +1,28 @@
# GetAllScenes
Get all loaded scenes.
## Syntax
```cpp
std::vector<Scene*> GetAllScenes() const;
```
## Returns
Returns a `std::vector` containing pointers to all loaded scenes.
## See Also
- [GetScene](get-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
for (Scene* scene : manager.GetAllScenes()) {
XC_LOG_INFO("Scene: {}", scene->GetName());
}
}
```

View File

@@ -0,0 +1,33 @@
# GetScene
Get a scene by name.
## Syntax
```cpp
Scene* GetScene(const std::string& name) const;
```
## Parameters
- `name` - The name of the scene.
## Returns
Returns a pointer to the scene with the specified name, or `nullptr` if not found.
## See Also
- [GetAllScenes](get-all-scenes)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
Scene* scene = manager.GetScene("Level1");
if (scene) {
XC_LOG_INFO("Found scene: {}", scene->GetName());
}
}
```

View File

@@ -0,0 +1,25 @@
# Get
Get the singleton SceneManager instance.
## Syntax
```cpp
static SceneManager& Get();
```
## Returns
Returns a reference to the singleton `SceneManager` instance.
## Remarks
Access the SceneManager singleton through this static method. The SceneManager is created on first access.
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
}
```

View File

@@ -0,0 +1,34 @@
# LoadSceneAsync
Load a scene from a file asynchronously.
## Syntax
```cpp
void LoadSceneAsync(const std::string& filePath, std::function<void(Scene*)> callback);
```
## Parameters
- `filePath` - The path to the scene file.
- `callback` - Callback function called when loading is complete, receives the loaded Scene.
## Remarks
Loads a scene from the specified file path asynchronously. The callback is invoked when loading is complete with a pointer to the loaded scene.
## See Also
- [LoadScene](load-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.LoadSceneAsync("assets/scenes/level1.scene", [](Scene* scene) {
XC_LOG_INFO("Scene loaded: {}", scene->GetName());
manager.SetActiveScene(scene);
});
}
```

View File

@@ -0,0 +1,31 @@
# LoadScene
Load a scene from a file synchronously.
## Syntax
```cpp
void LoadScene(const std::string& filePath);
```
## Parameters
- `filePath` - The path to the scene file.
## Remarks
Loads a scene from the specified file path. This is a synchronous operation and will block until the scene is fully loaded.
## See Also
- [LoadSceneAsync](load-scene-async)
- [CreateScene](create-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.LoadScene("assets/scenes/level1.scene");
}
```

View File

@@ -0,0 +1,33 @@
# OnActiveSceneChanged
Event triggered when the active scene changes.
## Syntax
```cpp
Core::Event<Scene*>& OnActiveSceneChanged();
```
## Returns
Returns a reference to the `Core::Event<Scene*>` for this event.
## Remarks
Subscribe to this event to be notified when the active scene changes.
## See Also
- [SetActiveScene](set-active-scene)
- [GetActiveScene](get-active-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.OnActiveSceneChanged().AddCallback([](Scene* scene) {
XC_LOG_INFO("Active scene changed: {}", scene->GetName());
});
}
```

View File

@@ -0,0 +1,33 @@
# OnSceneLoaded
Event triggered when a scene is loaded.
## Syntax
```cpp
Core::Event<Scene*>& OnSceneLoaded();
```
## Returns
Returns a reference to the `Core::Event<Scene*>` for this event.
## Remarks
Subscribe to this event to be notified when a scene is loaded.
## See Also
- [OnSceneUnloaded](on-scene-unloaded)
- [OnActiveSceneChanged](on-active-scene-changed)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.OnSceneLoaded().AddCallback([](Scene* scene) {
XC_LOG_INFO("Scene loaded: {}", scene->GetName());
});
}
```

View File

@@ -0,0 +1,33 @@
# OnSceneUnloaded
Event triggered when a scene is unloaded.
## Syntax
```cpp
Core::Event<Scene*>& OnSceneUnloaded();
```
## Returns
Returns a reference to the `Core::Event<Scene*>` for this event.
## Remarks
Subscribe to this event to be notified when a scene is unloaded.
## See Also
- [OnSceneLoaded](on-scene-loaded)
- [OnActiveSceneChanged](on-active-scene-changed)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.OnSceneUnloaded().AddCallback([](Scene* scene) {
XC_LOG_INFO("Scene unloaded: {}", scene->GetName());
});
}
```

View File

@@ -0,0 +1,74 @@
# SceneManager
**命名空间**: `XCEngine::Components`
**类型**: `class (singleton)`
**头文件**: `XCEngine/Scene/SceneManager.h`
**描述**: 场景管理器单例,管理所有场景和活动场景。
## 概述
SceneManager 是 XCEngine 中的场景管理器单例,负责管理所有加载的场景、场景切换(同步/异步)、设置活动场景,以及发布场景加载/卸载事件。它是场景系统的入口点,提供场景创建、加载、卸载和切换的接口。
## 单例访问
| 方法 | 描述 |
|------|------|
| `static SceneManager& Get()` | 获取场景管理器单例实例 |
## 公共方法
### 场景管理
| 方法 | 描述 |
|------|------|
| [`CreateScene`](create-scene.md) | 创建新场景 |
| [`LoadScene`](load-scene.md) | 同步加载场景 |
| [`LoadSceneAsync`](load-scene-async.md) | 异步加载场景 |
| [`UnloadScene`](unload-scene.md) | 卸载场景 |
### 活动场景
| 方法 | 描述 |
|------|------|
| [`SetActiveScene`](set-active-scene.md) | 设置活动场景 |
| [`GetActiveScene`](get-active-scene.md) | 获取当前活动场景 |
### 查找
| 方法 | 描述 |
|------|------|
| [`GetScene`](get-scene.md) | 按名称获取场景 |
| [`GetAllScenes`](get-all-scenes.md) | 获取所有场景 |
### 事件
| 方法 | 描述 |
|------|------|
| [`OnSceneLoaded`](on-scene-loaded.md) | 场景加载完成事件 |
| [`OnSceneUnloaded`](on-scene-unloaded.md) | 场景卸载完成事件 |
| [`OnActiveSceneChanged`](on-active-scene-changed.md) | 活动场景变更事件 |
## 使用示例
```cpp
#include <XCEngine/Scene/SceneManager.h>
using namespace XCEngine::Components;
void SceneManagerExample() {
Scene* scene = SceneManager::Get().CreateScene("GameLevel");
SceneManager::Get().SetActiveScene(scene);
SceneManager::Get().LoadSceneAsync("levels/menu.json", [](Scene* loadedScene) {
printf("Scene loaded: %s\n", loadedScene->GetName().c_str());
});
}
```
## 相关文档
- [Scene 模块总览](../scene.md) - Scene 模块总览
- [Scene](scene/scene.md) - 场景类

View File

@@ -0,0 +1,32 @@
# SetActiveScene
Set the currently active scene.
## Syntax
```cpp
void SetActiveScene(Scene* scene);
void SetActiveScene(const std::string& sceneName);
```
## Parameters
- `scene` - Pointer to the scene to set as active.
- `sceneName` - Name of the scene to set as active.
## Remarks
Sets which scene is currently active. The active scene is the one that receives updates.
## See Also
- [GetActiveScene](get-active-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.SetActiveScene("Level1");
}
```

View File

@@ -0,0 +1,33 @@
# UnloadScene
Unload a scene.
## Syntax
```cpp
void UnloadScene(Scene* scene);
void UnloadScene(const std::string& sceneName);
```
## Parameters
- `scene` - Pointer to the scene to unload.
- `sceneName` - Name of the scene to unload.
## Remarks
Removes a scene from the SceneManager. The scene and all its GameObjects will be destroyed.
## See Also
- [CreateScene](create-scene)
- [LoadScene](load-scene)
## Examples
```cpp
void Example() {
SceneManager& manager = SceneManager::Get();
manager.UnloadScene("Level1");
}
```