-
-
Save Bananaft/797f0291ede5451d9f50f4126b56ea3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Node::SetPrefab(const ResourceRef& value) | |
{ | |
UnsubscribeFromEvent(prefab_, E_RELOADFINISHED); | |
if (value.name_.Empty()) | |
{ | |
prefab_ = NULL; | |
} | |
else { | |
ResourceCache* cache = GetSubsystem<ResourceCache>(); | |
XMLFile* file = cache->GetResource<XMLFile>(value.name_); | |
if (file != NULL) | |
{ | |
URHO3D_LOGINFO("Loading node prefab: " + value.name_); | |
SceneResolver resolver; | |
Vector3 opos = position_; | |
Quaternion orot = rotation_; | |
Vector3 oscale = scale_; | |
LoadXML(file->GetRoot(), resolver, true, true, LOCAL); | |
SetTransform(opos, orot, oscale); | |
prefab_ = file; | |
} else { | |
URHO3D_LOGWARNING("Prefab loading error, no such file: " + value.name_); | |
} | |
SubscribeToEvent(prefab_, E_RELOADFINISHED, URHO3D_HANDLER(Node, HandlePrefabReload)); | |
} | |
} | |
void Node::HandlePrefabReload(StringHash eventType, VariantMap& eventData) | |
{ | |
ResourceRef ref = ResourceRef(XMLFile::GetTypeStatic(),prefab_->GetName()); | |
prefab_.Reset(); | |
SetPrefab(ref); | |
} | |
ResourceRef Node::GetPrefab() const | |
{ | |
return GetResourceRef(prefab_, XMLFile::GetTypeStatic()); | |
} | |
void Node::SavePrefab(bool b) | |
{ | |
if (prefab_ != NULL && b) | |
{ | |
SharedPtr<XMLFile> xmlFile = prefab_; | |
XMLElement nodeEl = xmlFile->CreateRoot("Node"); | |
//UBERHACK ENGAGE!!!!!11111 | |
prefab_ = NULL; | |
bool saveResult = SaveXML(nodeEl); | |
prefab_ = xmlFile; | |
if (saveResult) | |
{ | |
//prefab_->GetRoot() = nodeEl; | |
ResourceCache* cache = GetSubsystem<ResourceCache>(); | |
File file(context_, cache->GetResourceFileName(prefab_->GetName()), FILE_WRITE); | |
prefab_->Save(file); | |
URHO3D_LOGINFO("Prefab saved"); | |
} | |
else { | |
URHO3D_LOGINFO("Unable to save xml element"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment