2
0

BsCmdInstantiateSO.cpp 853 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "BsCmdInstantiateSO.h"
  2. #include "BsSceneObject.h"
  3. #include "BsPrefab.h"
  4. namespace BansheeEngine
  5. {
  6. CmdInstantiateSO::CmdInstantiateSO(const WString& description, const HPrefab& prefab)
  7. :EditorCommand(description), mPrefab(prefab)
  8. {
  9. }
  10. CmdInstantiateSO::~CmdInstantiateSO()
  11. {
  12. }
  13. HSceneObject CmdInstantiateSO::execute(const HPrefab& prefab, const WString& description)
  14. {
  15. // Register command and commit it
  16. CmdInstantiateSO* command = new (bs_alloc<CmdInstantiateSO>()) CmdInstantiateSO(description, prefab);
  17. UndoRedo::instance().registerCommand(command);
  18. command->commit();
  19. return command->mSceneObject;
  20. }
  21. void CmdInstantiateSO::commit()
  22. {
  23. mSceneObject = mPrefab->instantiate();
  24. }
  25. void CmdInstantiateSO::revert()
  26. {
  27. if (!mSceneObject.isDestroyed())
  28. mSceneObject->destroy(true);
  29. mSceneObject = nullptr;
  30. }
  31. }