BsCmdCreateSO.cpp 868 B

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