docs: expand gameobject helper docs
This commit is contained in:
@@ -1,41 +1,49 @@
|
||||
# GameObject::GameObject()
|
||||
# GameObject::Constructor
|
||||
|
||||
构造对象。
|
||||
构造一个 `GameObject`。
|
||||
|
||||
该方法在 `XCEngine/Components/GameObject.h` 中提供了 2 个重载,当前页面统一汇总这些公开声明。
|
||||
|
||||
## 重载 1: 声明
|
||||
`GameObject` 当前提供两个公开构造形式:
|
||||
|
||||
```cpp
|
||||
GameObject();
|
||||
```
|
||||
|
||||
**参数:** 无。
|
||||
|
||||
**返回:** `void` - 无返回值。
|
||||
|
||||
## 重载 2: 声明
|
||||
|
||||
```cpp
|
||||
explicit GameObject(const std::string& name);
|
||||
```
|
||||
|
||||
**参数:**
|
||||
- `name` - 参数语义详见头文件声明。
|
||||
## 默认构造行为
|
||||
|
||||
**返回:** `void` - 无返回值。
|
||||
默认构造当前会建立如下初始状态:
|
||||
|
||||
**示例:**
|
||||
- `name = "GameObject"`
|
||||
- `tag = "Untagged"`
|
||||
- `activeSelf = true`
|
||||
- `started = false`
|
||||
- `layer = 0`
|
||||
- `scene = nullptr`
|
||||
- `parent = nullptr`
|
||||
- 自动创建一个内建 `TransformComponent`
|
||||
- 分配新的递增 ID 与随机 UUID
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Components/GameObject.h>
|
||||
`tests/Components/test_game_object.cpp` 中的 `DefaultConstructor_DefaultValues` 已验证默认 `tag`、`layer`、激活态和 `Transform` 都会按这套语义建立。
|
||||
|
||||
void Example() {
|
||||
XCEngine::Components::GameObject object;
|
||||
}
|
||||
```
|
||||
## 命名构造行为
|
||||
|
||||
带 `name` 的构造只会把对象名替换为传入值,其他默认状态保持一致:
|
||||
|
||||
- `tag` 仍是 `"Untagged"`
|
||||
- `layer` 仍是 `0`
|
||||
- 仍然会创建内建 `Transform`
|
||||
- 仍然不会自动加入任何 `Scene`
|
||||
|
||||
## 重要边界
|
||||
|
||||
- 直接构造对象不会自动注册到全局 registry
|
||||
- 不会自动触发 `Awake()`
|
||||
- 不会自动接入场景层级
|
||||
|
||||
如果你需要完整运行时语义,应优先通过 [Scene::CreateGameObject](../../Scene/Scene/CreateGameObject.md) 创建。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [返回类总览](GameObject.md)
|
||||
- [返回模块目录](../Components.md)
|
||||
- [GameObject](GameObject.md)
|
||||
- [GetTransform](GetTransform.md)
|
||||
- [Scene::CreateGameObject](../../Scene/Scene/CreateGameObject.md)
|
||||
|
||||
Reference in New Issue
Block a user