docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档 - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览 - 修复 get-position.md 格式 - 更新 components.md 模块总览 - scene: 修复方法文档格式,新增缺失方法 - 修复 find.md, create-game-object.md 英文标题 - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档 - 更新 scene.md 类总览方法列表
This commit is contained in:
@@ -71,4 +71,4 @@ void SceneManagerExample() {
|
||||
## 相关文档
|
||||
|
||||
- [Scene 模块总览](../scene.md) - Scene 模块总览
|
||||
- [Scene](scene/scene.md) - 场景类
|
||||
- [Scene](../scene.md) - 场景类
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
# CreateGameObject
|
||||
# Scene::CreateGameObject
|
||||
|
||||
Create a new GameObject in this scene.
|
||||
|
||||
## Syntax
|
||||
在场景中创建新的 GameObject。
|
||||
|
||||
```cpp
|
||||
GameObject* CreateGameObject(const std::string& name, GameObject* parent = nullptr);
|
||||
```
|
||||
|
||||
## Parameters
|
||||
创建一个具有指定名称的新 GameObject,并可选择设置其父对象。GameObject 由场景拥有,当场景被销毁时也会被销毁。
|
||||
|
||||
- `name` - The name of the new GameObject.
|
||||
- `parent` - Optional parent GameObject (defaults to `nullptr`).
|
||||
**参数:**
|
||||
- `name` - 新 GameObject 的名称
|
||||
- `parent` - 可选的父 GameObject(默认为 `nullptr`)
|
||||
|
||||
## Returns
|
||||
**返回:** `GameObject*` - 指向新创建的 GameObject 的指针
|
||||
|
||||
Returns a pointer to the newly created `GameObject`.
|
||||
**线程安全:** ❌ (非线程安全,应在主线程调用)
|
||||
|
||||
## Remarks
|
||||
|
||||
Creates a new GameObject with the specified name and optionally sets its parent. The GameObject is owned by the scene and will be destroyed when the scene is destroyed.
|
||||
|
||||
## See Also
|
||||
|
||||
- [DestroyGameObject](destroy-game-object)
|
||||
|
||||
## Examples
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
|
||||
using namespace XCEngine::Components;
|
||||
|
||||
void Example(Scene* scene) {
|
||||
GameObject* player = scene->CreateGameObject("Player");
|
||||
GameObject* weapon = scene->CreateGameObject("Sword", player);
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Scene 总览](scene.md) - 返回类总览
|
||||
- [DestroyGameObject](destroy-game-object.md) - 销毁 GameObject
|
||||
|
||||
40
docs/api/scene/scene/deserialize-from-string.md
Normal file
40
docs/api/scene/scene/deserialize-from-string.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Scene::DeserializeFromString
|
||||
|
||||
从字符串反序列化场景。
|
||||
|
||||
```cpp
|
||||
void DeserializeFromString(const std::string& data);
|
||||
```
|
||||
|
||||
从 JSON 格式的字符串数据恢复场景的完整状态,包括所有 GameObject、组件和层级结构。
|
||||
|
||||
**参数:**
|
||||
- `data` - JSON 格式的序列化数据
|
||||
|
||||
**线程安全:** ❌ (非线程安全,应在主线程调用)
|
||||
|
||||
**注意:**
|
||||
- 此操作会清空当前场景的所有数据
|
||||
- 反序列化后的 GameObject 引用可能与原始引用不同
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
|
||||
using namespace XCEngine::Components;
|
||||
|
||||
void Example(Scene* scene) {
|
||||
std::string data = R"({
|
||||
"name": "GameScene",
|
||||
"gameObjects": [...]
|
||||
})";
|
||||
scene->DeserializeFromString(data);
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Scene 总览](scene.md) - 返回类总览
|
||||
- [Save](save.md) - 保存到文件
|
||||
- [SerializeToString](serialize-to-string.md) - 序列化为字符串
|
||||
36
docs/api/scene/scene/find-by-id.md
Normal file
36
docs/api/scene/scene/find-by-id.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Scene::FindByID
|
||||
|
||||
按 ID 查找 GameObject。
|
||||
|
||||
```cpp
|
||||
GameObject* FindByID(GameObjectID id) const;
|
||||
```
|
||||
|
||||
通过游戏对象的唯一标识符查找 GameObject。
|
||||
|
||||
**参数:**
|
||||
- `id` - GameObject 的唯一标识符
|
||||
|
||||
**返回:** `GameObject*` - 指向找到的 GameObject 的指针,未找到则返回 `nullptr`
|
||||
|
||||
**线程安全:** ✅ (只读操作)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
|
||||
using namespace XCEngine::Components;
|
||||
|
||||
void Example(Scene* scene, GameObjectID id) {
|
||||
GameObject* obj = scene->FindByID(id);
|
||||
if (obj) {
|
||||
printf("Found object: %s\n", obj->GetName().c_str());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Scene 总览](scene.md) - 返回类总览
|
||||
- [Find](find.md) - 按名称查找
|
||||
@@ -1,36 +1,36 @@
|
||||
# Find
|
||||
# Scene::Find
|
||||
|
||||
Find a GameObject by name.
|
||||
|
||||
## Syntax
|
||||
按名称查找 GameObject。
|
||||
|
||||
```cpp
|
||||
GameObject* Find(const std::string& name) const;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
在场景中搜索具有指定名称的 GameObject。搜索包括所有根对象及其子对象。
|
||||
|
||||
- `name` - The name of the GameObject to find.
|
||||
**参数:**
|
||||
- `name` - 要查找的 GameObject 名称
|
||||
|
||||
## Returns
|
||||
**返回:** `GameObject*` - 指向找到的 GameObject 的指针,未找到则返回 `nullptr`
|
||||
|
||||
Returns a pointer to the GameObject with the specified name, or `nullptr` if not found.
|
||||
**线程安全:** ✅ (只读操作)
|
||||
|
||||
## Remarks
|
||||
|
||||
Searches the scene for a GameObject with the specified name. The search includes all root GameObjects and their children.
|
||||
|
||||
## See Also
|
||||
|
||||
- [FindGameObjectWithTag](find-game-object-with-tag)
|
||||
|
||||
## Examples
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
|
||||
using namespace XCEngine::Components;
|
||||
|
||||
void Example(Scene* scene) {
|
||||
GameObject* player = scene->Find("Player");
|
||||
if (player) {
|
||||
XC_LOG_INFO("Found player!");
|
||||
printf("Found player!\n");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Scene 总览](scene.md) - 返回类总览
|
||||
- [FindGameObjectWithTag](find-game-object-with-tag.md) - 按标签查找
|
||||
|
||||
@@ -42,6 +42,7 @@ Scene 是 XCEngine 中的场景类,代表一个独立的游戏空间(如主
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Find`](find.md) | 按名称查找 GameObject |
|
||||
| [`FindByID`](find-by-id.md) | 按 ID 查找 GameObject |
|
||||
| [`FindGameObjectWithTag`](find-game-object-with-tag.md) | 按标签查找 GameObject |
|
||||
| [`FindObjectOfType`](find-object-of-type.md) | 查找指定类型的组件 |
|
||||
| [`FindObjectsOfType`](find-objects-of-type.md) | 查找所有指定类型的组件 |
|
||||
@@ -54,8 +55,10 @@ Scene 是 XCEngine 中的场景类,代表一个独立的游戏空间(如主
|
||||
| [`Update`](update.md) | 每帧更新场景 |
|
||||
| [`FixedUpdate`](fixed-update.md) | 固定频率更新 |
|
||||
| [`LateUpdate`](late-update.md) | 晚更新 |
|
||||
| [`Load`](load.md) | 加载场景 |
|
||||
| [`Save`](save.md) | 保存场景 |
|
||||
| [`Load`](load.md) | 从文件加载场景 |
|
||||
| [`Save`](save.md) | 保存场景到文件 |
|
||||
| [`SerializeToString`](serialize-to-string.md) | 序列化为字符串 |
|
||||
| [`DeserializeFromString`](deserialize-from-string.md) | 从字符串反序列化 |
|
||||
|
||||
### 事件
|
||||
|
||||
@@ -86,5 +89,5 @@ void SceneExample(Scene* scene) {
|
||||
## 相关文档
|
||||
|
||||
- [Scene 模块总览](../scene.md) - Scene 模块总览
|
||||
- [SceneManager](scene-manager/scene-manager.md) - 场景管理器
|
||||
- [GameObject](../components/game-object/game-object.md) - 游戏对象
|
||||
- [SceneManager](../scene-manager/scene-manager.md) - 场景管理器
|
||||
- [GameObject](../../components/game-object/game-object.md) - 游戏对象
|
||||
|
||||
33
docs/api/scene/scene/serialize-to-string.md
Normal file
33
docs/api/scene/scene/serialize-to-string.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Scene::SerializeToString
|
||||
|
||||
将场景序列化为字符串。
|
||||
|
||||
```cpp
|
||||
std::string SerializeToString() const;
|
||||
```
|
||||
|
||||
将场景的所有数据(包括所有 GameObject、组件和层级结构)序列化为 JSON 格式的字符串。
|
||||
|
||||
**返回:** `std::string` - 序列化后的 JSON 字符串
|
||||
|
||||
**线程安全:** ✅ (只读操作)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
|
||||
using namespace XCEngine::Components;
|
||||
|
||||
void Example(Scene* scene) {
|
||||
std::string serialized = scene->SerializeToString();
|
||||
printf("Serialized scene (%zu bytes):\n%s\n",
|
||||
serialized.size(), serialized.c_str());
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Scene 总览](scene.md) - 返回类总览
|
||||
- [Load](load.md) - 从文件加载
|
||||
- [DeserializeFromString](deserialize-from-string.md) - 从字符串反序列化
|
||||
Reference in New Issue
Block a user