5#include "../Manager/SCloneFactory.h"
6#include "../Manager/ResMgr.h"
8#include "../Util/Loader/DAE/DAELoader.h"
9#include "../Util/AssetsDef.h"
10#include "SGameObjectFromSPrefab.h"
14SPrefab::SPrefab() =
default;
16SPrefab::~SPrefab() =
default;
18void SPrefab::Exterminate() {
22 SGameObject* clone = SCloneFactory::Clone(m_root, parent);
24 clone->GetTransform()->m_position =
vec3(position);
25 clone->SetIsPrefab(
false);
26 clone->SetUndestroyable(
false);
33 SGameObject* clone = SCloneFactory::Clone(m_root, parent);
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);
45 if (m_root !=
nullptr)
return false;
48 m_root->SetUndestroyable(
true);
49 m_root->SetIsPrefab(
true);
50 m_root->SetResourceID(GetHash(),
true);
56 AssetMgr::TYPE type = asset->type;
57 std::string path = asset->name_path;
61 DAELoader::GeneratePrefab(path.c_str(),
nullptr,
nullptr,
nullptr,
this);
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;
71 const auto& hashChildren = hashData.children;
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);
82 for(
const auto& child : hashChildren) {
83 const auto&
id = child.getAttribute(
"id").value;
84 std::string hash = child.value;
86 if(obj ==
nullptr)
continue;
88 obj->SetRefHash(hash);
99 obj->SetResourceID(GetHash());
101 std::string resultID = obj->GetID();
102 resultID = resultID.substr(resultID.find(
'/') + 1);
103 obj->SetResourceID(std::string(GetHash()) +
"*" + resultID);
106 for (
auto child : obj->GetChildren()) {
107 GenerateResourceID(child);