ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Behavior.h
浏览该文件的文档.
1#pragma once
2#include "Component.h"
3
4namespace Shit {
5 class GameObject;
6
22 class SHIT_API SHIT_REFLECT(BlackList) Behavior : public Component {
23 friend class GameObject;
25 public:
26 Behavior() = default;
27 ~Behavior() override = default;
28
29 // --- 生命周期 ---
30 void onCreate() override;
31 void onAttach() override;
32 virtual void onStart();
33 virtual void onFixedUpdate(float fixedDt);
34 virtual void onUpdate();
35
36 // --- 碰撞回调(由 PhysicsSystem2D 驱动;仅 onStart 已执行的行为可收到) ---
37 virtual void onCollisionEnter(GameObject* other);
38 virtual void onCollisionStay(GameObject* other);
39 virtual void onCollisionExit(GameObject* other);
40
41 void onDetach() override;
42 void onDestroy() override;
43
44 bool isStarted() const { return m_isStarted; }
46
47 protected:
48 SHIT_META(({.displayName = "Started", .tooltip = "onStart 是否已执行过", .readOnly = true}))
49 bool m_isStarted = false;
50 };
51}
#define SHIT_API
定义 Core.h:14
#define SHIT_REFLECT_BODY(Type)
定义 Macros.h:89
#define SHIT_REFLECT(Mode)
定义 Macros.h:86
#define SHIT_META(...)
定义 Macros.h:95
friend class GameObject
定义 Behavior.h:23
bool m_isStarted
定义 Behavior.h:49
virtual void onCollisionEnter(GameObject *other)
与 other 开始接触(每对象对一次)
virtual void onCollisionStay(GameObject *other)
与 other 持续接触(每帧一次)
Behavior()=default
~Behavior() override=default
virtual void onStart()
首次 update 前执行一次
void setStarted(bool isStarted)
定义 Behavior.h:45
virtual void onFixedUpdate(float fixedDt)
固定步长执行(与物理同拍;Scene 固定步循环驱动)
bool isStarted() const
onStart 是否已执行过
定义 Behavior.h:44
virtual void onUpdate()
每帧执行
void onCreate() override
void onAttach() override
void onDetach() override
void onDestroy() override
virtual void onCollisionExit(GameObject *other)
与 other 结束接触
游戏物体类
定义 GameObject.h:23
定义 AnimationClip.h:12