BsCmdInstantiateSO.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "UndoRedo/BsCmdInstantiateSO.h"
  4. #include "Scene/BsSceneObject.h"
  5. #include "Scene/BsPrefab.h"
  6. namespace bs
  7. {
  8. CmdInstantiateSO::CmdInstantiateSO(const String& description, const HPrefab& prefab)
  9. :EditorCommand(description), mPrefab(prefab)
  10. { }
  11. HSceneObject CmdInstantiateSO::execute(const HPrefab& prefab, const String& description)
  12. {
  13. // Register command and commit it
  14. CmdInstantiateSO* command = new (bs_alloc<CmdInstantiateSO>()) CmdInstantiateSO(description, prefab);
  15. SPtr<CmdInstantiateSO> commandPtr = bs_shared_ptr(command);
  16. UndoRedo::instance().registerCommand(commandPtr);
  17. commandPtr->commit();
  18. return commandPtr->mSceneObject;
  19. }
  20. void CmdInstantiateSO::commit()
  21. {
  22. mSceneObject = mPrefab->instantiate();
  23. }
  24. void CmdInstantiateSO::revert()
  25. {
  26. if (!mSceneObject.isDestroyed())
  27. mSceneObject->destroy(true);
  28. mSceneObject = nullptr;
  29. }
  30. }