|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
游戏物体类 更多...
#include <GameObject.h>
Public 成员函数 | |
| ~GameObject ()=default | |
| GameObject (const GameObject &)=delete | |
| GameObject & | operator= (const GameObject &)=delete |
| GameObject (GameObject &&)=delete | |
| GameObject & | operator= (GameObject &&)=delete |
| void | destroy () |
| 标记为待销毁(帧末由 Scene 统一清理) | |
| const std::string & | getName () const |
| const std::string & | getTag () const |
| Scene * | getScene () const |
| bool | isNeedDestroy () const |
| void | setName (const std::string &name) |
| void | setTag (const std::string &tag) |
| 设置标签(用于分类,如 "enemy"、"player") | |
| void | setScene (Scene *scene) |
| 设置所属场景(同时触发未注册组件的 onAttach) | |
| void | setNeedDestroy (bool needDestroy) |
| std::unordered_map< std::type_index, std::unique_ptr< Component > > & | getComponents () |
| 获取全部组件(按 type_index 索引) | |
| template<typename T, typename... Args> | |
| T * | addComponent (Args &&... args) |
| 添加组件 | |
| template<typename T> | |
| T * | getComponent () |
| 获取组件 | |
| template<typename T> | |
| bool | hasComponent () |
| 检查是否存在某个组件 | |
| template<typename T> | |
| void | removeComponent () |
| 移除某个组件 | |
友元 | |
| class | Scene |
游戏物体类
构造函数私有,只能通过 Scene::createGameObject 或 Scene::instantiate 创建。
|
default |
|
delete |
|
delete |
|
inline |
添加组件
| T | 组件类型(须继承 Component) |
| Args | 构造参数类型 |
| args | 传递给组件构造函数 |
| void destroy | ( | ) |
标记为待销毁(帧末由 Scene 统一清理)
|
inline |
获取组件
| T | 组件类型 |
|
inline |
获取全部组件(按 type_index 索引)
|
inline |
|
inline |
|
inline |
|
inline |
检查是否存在某个组件
| T | 组件类型 |
|
inline |
|
delete |
|
delete |
|
inline |
移除某个组件
| T | 组件类型 |
生命周期调用顺序:onDetach → onDestroy
|
inline |
|
inline |
| void setScene | ( | Scene * | scene | ) |
设置所属场景(同时触发未注册组件的 onAttach)
|
inline |
设置标签(用于分类,如 "enemy"、"player")
|
friend |