55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
// src/Components/GameObject.h
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <memory>
|
|
|
|
#include "Component.h"
|
|
#include "Transform.h"
|
|
#include "ScriptComponent.h"
|
|
#include "Mesh.h"
|
|
#include "CameraComponent.h"
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
// GetComponent<CameraComponent>()
|
|
|
|
class GameObject
|
|
{
|
|
public:
|
|
int id;
|
|
std::string name;
|
|
std::unordered_map<std::string, std::shared_ptr<Component>> components;
|
|
|
|
int GetComponentCount() const;
|
|
|
|
GameObject(int id, const std::string &name);
|
|
|
|
std::string GetName() const;
|
|
|
|
void AddComponent(const std::shared_ptr<Component> &component);
|
|
bool RemoveComponent(const std::shared_ptr<Component> &component);
|
|
|
|
|
|
|
|
std::shared_ptr<Component> GetComponentByName(const std::string &name) const;
|
|
|
|
void Update(float deltaTime);
|
|
|
|
template <typename T>
|
|
std::shared_ptr<T> GetComponent()
|
|
{
|
|
auto it = components.find(T::GetStaticName());
|
|
if (it != components.end())
|
|
{
|
|
return std::dynamic_pointer_cast<T>(it->second);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
// Serialization methods
|
|
YAML::Node Serialize();
|
|
void Deserialize(const YAML::Node &node);
|
|
};
|