BsCmdInstantiateSO.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. }
  12. CmdInstantiateSO::~CmdInstantiateSO()
  13. {
  14. }
  15. HSceneObject CmdInstantiateSO::execute(const HPrefab& prefab, const String& description)
  16. {
  17. // Register command and commit it
  18. CmdInstantiateSO* command = new (bs_alloc<CmdInstantiateSO>()) CmdInstantiateSO(description, prefab);
  19. SPtr<CmdInstantiateSO> commandPtr = bs_shared_ptr(command);
  20. UndoRedo::instance().registerCommand(commandPtr);
  21. commandPtr->commit();
  22. return commandPtr->mSceneObject;
  23. }
  24. void CmdInstantiateSO::commit()
  25. {
  26. mSceneObject = mPrefab->instantiate();
  27. }
  28. void CmdInstantiateSO::revert()
  29. {
  30. if (!mSceneObject.isDestroyed())
  31. mSceneObject->destroy(true);
  32. mSceneObject = nullptr;
  33. }
  34. }