BsCmdCreateSO.cpp 1.1 KB

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