CSEngine
Loading...
Searching...
No Matches
CSE::SPrefab Class Reference
Inheritance diagram for CSE::SPrefab:
CSE::SResource CSE::SObject

Public Member Functions

SGameObjectClone (const vec3 &position, SGameObject *parent=nullptr)
 
SGameObjectClone (const vec3 &position, const vec3 &scale, Quaternion rotation, SGameObject *parent=nullptr)
 
bool SetGameObject (SGameObject *obj)
 
void Exterminate () override
 
SGameObjectGetRoot () const
 
- Public Member Functions inherited from CSE::SResource
 SResource (bool isRegister)
 
 SResource (const SResource *resource, bool isRegister)
 
void SetName (std::string name)
 
void SetAbsoluteID (std::string id)
 
std::string GetName () const
 
std::string GetAbsoluteID () const
 
AssetMgr::AssetReferenceGetAssetReference (std::string hash="") const
 
void LinkResource (AssetMgr::AssetReference *asset)
 
void LinkResource (std::string name)
 
void SetHash (std::string &hash) override
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 

Protected Member Functions

void Init (const AssetMgr::AssetReference *asset) override
 
void GenerateResourceID (SGameObject *obj=nullptr)
 

Additional Inherited Members

- Static Public Member Functions inherited from CSE::SResource
template<class T >
static T * Create (const std::string &name)
 
template<class T >
static T * Create (const AssetMgr::AssetReference *asset)
 
template<class T >
static T * Get (std::string name)
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 11 of file SPrefab.h.

Member Function Documentation

◆ Clone() [1/2]

SGameObject * SPrefab::Clone ( const vec3 position,
const vec3 scale,
Quaternion  rotation,
SGameObject parent = nullptr 
)

Definition at line 32 of file SPrefab.cpp.

32 {
33 SGameObject* clone = SCloneFactory::Clone(m_root, parent);
34
35 clone->GetTransform()->m_position = vec3(position);
36 clone->GetTransform()->m_scale = vec3(scale);
37 clone->GetTransform()->m_rotation = Quaternion(rotation);
38 clone->SetIsPrefab(false);
39 clone->SetUndestroyable(false);
40
41 return clone;
42}

◆ Clone() [2/2]

SGameObject * SPrefab::Clone ( const vec3 position,
SGameObject parent = nullptr 
)

Definition at line 21 of file SPrefab.cpp.

21 {
22 SGameObject* clone = SCloneFactory::Clone(m_root, parent);
23
24 clone->GetTransform()->m_position = vec3(position);
25 clone->SetIsPrefab(false);
26 clone->SetUndestroyable(false);
27
28 return clone;
29}

◆ Exterminate()

void SPrefab::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 18 of file SPrefab.cpp.

18 {
19}

◆ GenerateResourceID()

void SPrefab::GenerateResourceID ( SGameObject obj = nullptr)
protected

Definition at line 96 of file SPrefab.cpp.

96 {
97 if (obj == nullptr) {
98 obj = m_root;
99 obj->SetResourceID(GetHash());
100 } else {
101 std::string resultID = obj->GetID();
102 resultID = resultID.substr(resultID.find('/') + 1);
103 obj->SetResourceID(std::string(GetHash()) + "*" + resultID);
104 }
105
106 for (auto child : obj->GetChildren()) {
107 GenerateResourceID(child);
108 }
109}

◆ GetRoot()

SGameObject * CSE::SPrefab::GetRoot ( ) const
inline

Definition at line 24 of file SPrefab.h.

24 {
25 return m_root;
26 }

◆ Init()

void SPrefab::Init ( const AssetMgr::AssetReference asset)
overrideprotectedvirtual

Implements CSE::SResource.

Definition at line 55 of file SPrefab.cpp.

55 {
56 AssetMgr::TYPE type = asset->type;
57 std::string path = asset->name_path;
58
59 switch (type) {
60 case AssetMgr::DAE:
61 DAELoader::GeneratePrefab(path.c_str(), nullptr, nullptr, nullptr, this);
62 break;
63 }
64
65 std::string hashRaw = AssetMgr::LoadAssetFile(path + ".meta");
66 if(!hashRaw.empty()) {
67 const XNode* root = XFILE().loadBuffer(hashRaw);
68 const auto& hashData = root->getNode("hash-data");
69 std::string hash = hashData.getAttribute("hash").value;
70 SetHash(hash);
71 const auto& hashChildren = hashData.children;
72
73 if(hashData.children.size() <= 0) {
74 hashRaw = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
75 "<CSEMETA version=\"1.0.0\">\n"
76 "<hash-data hash=\"" + m_hash + "\">\n"
77 + m_root->GenerateMeta() +
78 "\n</hash-data>\n</CSEMETA>";
79 SaveTxtFile(path + ".meta", hashRaw);
80 }
81 else {
82 for(const auto& child : hashChildren) {
83 const auto& id = child.getAttribute("id").value;
84 std::string hash = child.value;
85 const auto& obj = static_cast<SGameObjectFromSPrefab*>(m_root->FindLocalByID(id));
86 if(obj == nullptr) continue;
87 obj->SetHash(hash);
88 obj->SetRefHash(hash);
89 }
90 }
91 SAFE_DELETE(root);
92 }
93 GenerateResourceID();
94}
Definition XML.h:77
Definition XML.h:43

◆ SetGameObject()

bool SPrefab::SetGameObject ( SGameObject obj)

Definition at line 44 of file SPrefab.cpp.

44 {
45 if (m_root != nullptr) return false;
46
47 m_root = obj;
48 m_root->SetUndestroyable(true);
49 m_root->SetIsPrefab(true);
50 m_root->SetResourceID(GetHash(), true);
51
52 return true;
53}

The documentation for this class was generated from the following files: