BsCmdCreateSO.cpp 1.1 KB

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