| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "UndoRedo/BsCmdReparentSO.h"
- #include "Scene/BsSceneObject.h"
- namespace bs
- {
- CmdReparentSO::CmdReparentSO(const String& description, const Vector<HSceneObject>& sceneObjects, const HSceneObject& newParent)
- :EditorCommand(description), mSceneObjects(sceneObjects), mNewParent(newParent)
- {
- for(auto& sceneObject : mSceneObjects)
- {
- mOldParents.push_back(sceneObject->getParent());
- }
- }
- void CmdReparentSO::execute(const Vector<HSceneObject>& sceneObjects, const HSceneObject& newParent,
- const String& description)
- {
- // Register command and commit it
- CmdReparentSO* command = new (bs_alloc<CmdReparentSO>()) CmdReparentSO(description, sceneObjects, newParent);
- SPtr<CmdReparentSO> commandPtr = bs_shared_ptr(command);
- UndoRedo::instance().registerCommand(commandPtr);
- commandPtr->commit();
- }
- void CmdReparentSO::execute(HSceneObject& sceneObject, const HSceneObject& newParent, const String& description)
- {
- // Register command and commit it
- CmdReparentSO* command = new (bs_alloc<CmdReparentSO>()) CmdReparentSO(description, { sceneObject }, newParent);
- SPtr<CmdReparentSO> commandPtr = bs_shared_ptr(command);
- UndoRedo::instance().registerCommand(commandPtr);
- commandPtr->commit();
- }
- void CmdReparentSO::commit()
- {
- if(mNewParent.isDestroyed())
- return;
- UINT32 cnt = 0;
- for(auto& sceneObject : mSceneObjects)
- {
- if(!sceneObject.isDestroyed())
- sceneObject->setParent(mNewParent);
- cnt++;
- }
- }
- void CmdReparentSO::revert()
- {
- UINT32 cnt = 0;
- for(auto& sceneObject : mSceneObjects)
- {
- if(!sceneObject.isDestroyed() && !mOldParents[cnt].isDestroyed())
- sceneObject->setParent(mOldParents[cnt]);
- cnt++;
- }
- }
- }
|