18 m_parent->RemoveChild(
this);
22 for (
size_t i = 0; i < m_children.GetSize(); ++i) {
24 m_children[i]->m_parent =
nullptr;
31 for (
size_t i = 0; i < Components.GetSize(); ++i) {
33 Components[i]->Initialize();
39 if (!m_isActive || m_pendingDestroy)
return;
41 for (
size_t i = 0; i < Components.GetSize(); ++i) {
43 Components[i]->Update(deltaTime);
46 for (
size_t i = 0; i < m_children.GetSize(); ++i) {
47 if (m_children[i] && m_children[i]->
IsActive())
48 m_children[i]->Update(deltaTime);
53 if (!m_isActive || m_pendingDestroy)
return;
55 for (
size_t i = 0; i < Components.GetSize(); ++i) {
57 Components[i]->FixedUpdate(fixedDeltaTime);
60 for (
size_t i = 0; i < m_children.GetSize(); ++i) {
61 if (m_children[i] && m_children[i]->
IsActive())
62 m_children[i]->FixedUpdate(fixedDeltaTime);
67 if (!m_isActive || m_pendingDestroy)
return;
69 for (
size_t i = 0; i < Components.GetSize(); ++i) {
71 Components[i]->LateUpdate(deltaTime);
74 for (
size_t i = 0; i < m_children.GetSize(); ++i) {
75 if (m_children[i] && m_children[i]->
IsActive())
76 m_children[i]->LateUpdate(deltaTime);
81 if (m_isActive == active)
return;
84 for (
size_t i = 0; i < Components.GetSize(); ++i) {
87 Components[i]->OnEnable();
89 Components[i]->OnDisable();
93 for (
size_t i = 0; i < m_children.GetSize(); ++i) {
95 m_children[i]->SetActive(active);
100 if (m_parent == parent)
return;
103 m_parent->RemoveChild(
this);
109 if (m_parent->m_children.indexOf(
this) == -1) {
110 m_parent->m_children.add(
this);
116 if (!child || child ==
this)
return;
122 int index = m_children.indexOf(child);
124 m_children.erase(index);
125 child->m_parent =
nullptr;
129 void GameObject::DestroyComponents() {
130 for (
size_t i = 0; i < Components.GetSize(); ++i) {
132 Components[i]->OnDestroy();
140 mat->SetShader(
"assets/shaders/default_shader.hlsl");
Sleak::MeshData GetPlaneMesh(float width, float height, int subdivisionsX=1, int subdivisionsY=1)
Builds a subdivided flat quad on the XZ plane, facing up.
Sleak::MeshData GetCapsuleMesh(int segments, int rings, float height, float radius)
Builds a capsule (cylinder with hemispherical caps) centered at the origin.
Sleak::MeshData GetCylinderMesh(int segments, float height, float radius)
Builds a capped cylinder centered at the origin, extending +/- height/2 along Y.
Sleak::MeshData GetSphereMesh(int stacks=16, int slices=16)
Builds a UV sphere of unit radius with the given stack/slice resolution.
Sleak::MeshData GetCubeMesh()
Builds a unit cube with per-face vertices for hard-edged normals.
static GameObject * CreateCylinder(Math::Vector3D position, int segments=16, float height=1, float radius=0.5)
virtual void LateUpdate(float deltaTime)
virtual void Initialize()
Initializes the object and its components; called once before the first Update.
static GameObject * CreateCapsule(Math::Vector3D position, int segments=16, int rings=8, float height=1, float radius=0.5)
virtual void Update(float deltaTime)
void RemoveChild(GameObject *child)
virtual void FixedUpdate(float fixedDeltaTime)
GameObject(const std::string &name="GameObject")
void SetActive(bool active)
Enables or disables the object, firing OnEnable/OnDisable on its components.
static GameObject * CreatePlane(Math::Vector3D position, int width=100, int height=100)
Built-in primitive factories, mainly for prototyping and debug scenes.
static GameObject * CreateCube(Math::Vector3D position)
void AddChild(GameObject *child)
static GameObject * CreateSphere(Math::Vector3D position, int stack=16, int slices=16)
void SetParent(GameObject *parent)
Reparents this object, updating both the old and new parent's child lists.
virtual bool Initialize() override
Validates that vertex and index buffers were created successfully.
Root namespace for everything the engine exposes.
static Material * CreateDefaultMaterial()
Fallback material for the primitive factories below, using the default shader.