BsCmdInstantiateSO.cpp 1.1 KB

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