2025-01-04 04:12:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include "entities/SceneComponent.h"
|
|
|
|
#include "xml/tinyxml2.h"
|
|
|
|
|
|
|
|
class Entity : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2025-01-05 15:54:44 +00:00
|
|
|
explicit Entity(class WorkSpace* workspace);
|
2025-01-04 04:12:51 +00:00
|
|
|
explicit Entity(const QString& name, QObject* parent = nullptr);
|
|
|
|
~Entity();
|
|
|
|
|
|
|
|
virtual void Serialize(const tinyxml2::XMLElement* element);
|
|
|
|
virtual void UnSerialize(tinyxml2::XMLElement* element);
|
|
|
|
virtual bool SetAttribute(const char* name, const char* value);
|
|
|
|
virtual void Begin();
|
|
|
|
virtual void Update(double dt);
|
|
|
|
virtual void End();
|
|
|
|
virtual void Destory();
|
|
|
|
|
|
|
|
class Transform* GetTransform() const;
|
|
|
|
|
|
|
|
void SetUUid(const QString& uuid);
|
|
|
|
const QString& GetUUid() const {
|
|
|
|
return uuid_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnLoad();
|
|
|
|
const QString& GetName() const {
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
QString& GetName() {
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
void SetName(const QString& name);
|
|
|
|
|
|
|
|
void SetWorkspace(class WorkSpace* workspace);
|
|
|
|
class WorkSpace* GetWorkspace() const {
|
|
|
|
return workspace_;
|
|
|
|
}
|
|
|
|
void SetParent(Entity* parent);
|
|
|
|
Entity* GetParent() const {
|
|
|
|
return parent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T* GetComponent() {
|
|
|
|
if (nullptr == rootComponet_) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return rootComponet_->GetComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRootComponent(SceneComponent* root) {
|
|
|
|
rootComponet_ = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneComponent* GetRootComponent() const {
|
|
|
|
return rootComponet_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Entity*> GetChilder() const {
|
|
|
|
return childer_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void NameChanged(const QString& name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QString uuid_;
|
|
|
|
QString name_;
|
|
|
|
SceneComponent* rootComponet_{ nullptr };
|
|
|
|
bool isRunning_{ false };
|
|
|
|
|
|
|
|
class WorkSpace* workspace_{ nullptr };
|
|
|
|
Entity* parent_{ nullptr };
|
|
|
|
std::vector<Entity*> childer_;
|
|
|
|
|
|
|
|
class NetDriver* netDriver_{ nullptr };
|
|
|
|
};
|