docs: expand gameobject helper docs

This commit is contained in:
2026-04-03 16:11:48 +08:00
parent ee44e14960
commit 2c2e1fab1c
34 changed files with 597 additions and 603 deletions

View File

@@ -1,30 +1,30 @@
# GameObject::GetComponentInParent
获取相关状态或对象
沿父链向上查找第一个匹配组件
```cpp
template<typename T> T* GetComponentInParent();
template<typename T>
T* GetComponentInParent();
```
该方法声明于 `XCEngine/Components/GameObject.h`,当前页面用于固定 `GameObject` 类目录下的方法级 canonical 路径。
## 搜索顺序
**参数:** 无。
当前实现不会先检查当前对象自己,而是:
**返回:** `template<typename T> T*` - 返回值语义详见头文件声明。
1. 先看当前对象是否存在父节点
2. 对父对象调用 [GetComponent](GetComponent.md)
3. 若父对象未命中,则继续递归向更高层父节点查询
**示例:**
因此它返回的是“最近祖先链上第一个匹配组件”。
```cpp
#include <XCEngine/Components/GameObject.h>
## 当前语义边界
void Example() {
XCEngine::Components::GameObject object;
// 根据上下文补齐参数后调用 GameObject::GetComponentInParent(...)。
(void)object;
}
```
- 搜索范围不包含当前对象自己
- 若父对象存在匹配项,就不会继续往更高祖先找
- 对宽类型查询,父对象的 `TransformComponent` 仍可能优先命中
## 相关文档
- [返回类总览](GameObject.md)
- [返回模块目录](../Components.md)
- [GetComponent](GetComponent.md)
- [GetParent](GetParent.md)
- [GetComponentInChildren](GetComponentInChildren.md)