docs: expand gameobject helper docs
This commit is contained in:
@@ -1,42 +1,36 @@
|
||||
# GameObject::GetTransform
|
||||
|
||||
获取相关状态或对象。
|
||||
返回当前对象的内建 `TransformComponent`。
|
||||
|
||||
该方法在 `XCEngine/Components/GameObject.h` 中提供了 2 个重载,当前页面统一汇总这些公开声明。
|
||||
|
||||
## 重载 1: 声明
|
||||
该方法当前提供两个公开重载:
|
||||
|
||||
```cpp
|
||||
TransformComponent* GetTransform();
|
||||
```
|
||||
|
||||
**参数:** 无。
|
||||
|
||||
**返回:** `TransformComponent*` - 返回值语义详见头文件声明。
|
||||
|
||||
## 重载 2: 声明
|
||||
|
||||
```cpp
|
||||
const TransformComponent* GetTransform() const;
|
||||
```
|
||||
|
||||
**参数:** 无。
|
||||
## 行为说明
|
||||
|
||||
**返回:** `const TransformComponent*` - 返回值语义详见头文件声明。
|
||||
两个重载都直接返回底层 `m_transform` 指针。
|
||||
|
||||
**示例:**
|
||||
按当前对象模型:
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Components/GameObject.h>
|
||||
- 每个 `GameObject` 构造时都会创建一个 `TransformComponent`
|
||||
- `AddComponent<TransformComponent>()` 也只是返回这同一份实例
|
||||
- `RemoveComponent()` 不允许移除它
|
||||
|
||||
void Example() {
|
||||
XCEngine::Components::GameObject object;
|
||||
// 根据上下文补齐参数后调用 GameObject::GetTransform(...)。
|
||||
(void)object;
|
||||
}
|
||||
```
|
||||
因此在正常存活期内,这个接口应始终返回非空指针。
|
||||
|
||||
## 为什么它不是普通组件查询的简单别名
|
||||
|
||||
虽然 [GetComponent](GetComponent.md) 也可能返回 `TransformComponent`,但 `GetTransform()` 更明确:
|
||||
|
||||
- 它直接表达“我要对象的内建 Transform”
|
||||
- 不受模板匹配与搜索顺序歧义影响
|
||||
- 对编辑器、脚本桥接和空间变换代码更可读
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [返回类总览](GameObject.md)
|
||||
- [返回模块目录](../Components.md)
|
||||
- [GetComponent](GetComponent.md)
|
||||
- [AddComponent](AddComponent.md)
|
||||
- [TransformComponent](../TransformComponent/TransformComponent.md)
|
||||
|
||||
Reference in New Issue
Block a user