ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
Component.h
浏览该文件的文档.
1
#pragma once
2
#include "
../Core/Config.h
"
3
4
namespace
Shit
{
5
class
GameObject
;
// 前向声明
6
18
class
SHIT_API
Component
{
19
friend
class
GameObject
;
// 只能通过GameObject初始化组件
20
21
public
:
22
Component
();
23
virtual
~Component
() =
default
;
24
25
virtual
void
onCreate
() {}
// 组件创建时(有 owner,但可能尚未挂到场景)
26
virtual
void
onAttach
() {}
// 组件挂载到活动场景时
27
virtual
void
onDetach
() {}
// 组件从场景卸下时
28
virtual
void
onDestroy
() {}
// 组件销毁时
29
30
// 禁止拷贝和移动
31
Component
(
const
Component
&) =
delete
;
32
Component
&
operator=
(
const
Component
&) =
delete
;
33
Component
(
Component
&&) =
delete
;
34
Component
&
operator=
(
Component
&&) =
delete
;
35
36
GameObject
*
getOwner
()
const
{
return
m_owner
; }
37
bool
isRegistered
()
const
{
return
m_isRegistered
; }
38
39
private
:
40
// 只允许 GameObject 设置
41
inline
void
setOwner(
GameObject
* owner) { m_owner = owner; }
42
43
protected
:
44
GameObject
*
m_owner
=
nullptr
;
// 组件的拥有者
45
bool
m_isRegistered
=
false
;
46
};
47
}
Config.h
SHIT_API
#define SHIT_API
定义
Core.h:12
Shit::Component::GameObject
friend class GameObject
定义
Component.h:19
Shit::Component::Component
Component()
Shit::Component::operator=
Component & operator=(Component &&)=delete
Shit::Component::onDestroy
virtual void onDestroy()
定义
Component.h:28
Shit::Component::onCreate
virtual void onCreate()
定义
Component.h:25
Shit::Component::onAttach
virtual void onAttach()
定义
Component.h:26
Shit::Component::Component
Component(const Component &)=delete
Shit::Component::getOwner
GameObject * getOwner() const
定义
Component.h:36
Shit::Component::m_owner
GameObject * m_owner
定义
Component.h:44
Shit::Component::Component
Component(Component &&)=delete
Shit::Component::onDetach
virtual void onDetach()
定义
Component.h:27
Shit::Component::isRegistered
bool isRegistered() const
定义
Component.h:37
Shit::Component::~Component
virtual ~Component()=default
Shit::Component::operator=
Component & operator=(const Component &)=delete
Shit::Component::m_isRegistered
bool m_isRegistered
定义
Component.h:45
Shit::GameObject
游戏物体类
定义
GameObject.h:22
Shit
定义
AudioPlayer.h:9
ShitEngine
Component
Component.h
制作者
1.17.0