89 lines
1.8 KiB
C
89 lines
1.8 KiB
C
|
#pragma once
|
||
|
|
||
|
#include <unordered_map>
|
||
|
|
||
|
#include <QObject>
|
||
|
|
||
|
#include "entities/SceneComponent.h"
|
||
|
#include "xml/tinyxml2.h"
|
||
|
|
||
|
class Entity : public QObject {
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
|
explicit Entity(QObject* parent = nullptr);
|
||
|
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 };
|
||
|
};
|