BsCmdCreateSO.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "Scene/BsSelection.h"
  6. namespace bs
  7. {
  8. CmdCreateSO::CmdCreateSO(const String& description, const String& name, UINT32 flags)
  9. :EditorCommand(description), mName(name), mFlags(flags)
  10. { }
  11. CmdCreateSO::CmdCreateSO(const String& description, const String& name, const Vector<UINT32>& componentTypeIds,
  12. UINT32 flags)
  13. :EditorCommand(description), mName(name), mFlags(flags), mComponentTypeIds(componentTypeIds)
  14. { }
  15. HSceneObject CmdCreateSO::execute(const String& name, UINT32 flags, const String& description)
  16. {
  17. // Register command and commit it
  18. CmdCreateSO* command = new (bs_alloc<CmdCreateSO>()) CmdCreateSO(description, name, flags);
  19. SPtr<CmdCreateSO> commandPtr = bs_shared_ptr(command);
  20. UndoRedo::instance().registerCommand(commandPtr);
  21. commandPtr->commit();
  22. return commandPtr->mSceneObject;
  23. }
  24. HSceneObject CmdCreateSO::execute(const String& name, UINT32 flags, const Vector<UINT32>& componentTypeIds,
  25. const String& description)
  26. {
  27. // Register command and commit it
  28. CmdCreateSO* command = new (bs_alloc<CmdCreateSO>()) CmdCreateSO(description, name, componentTypeIds, flags);
  29. SPtr<CmdCreateSO> commandPtr = bs_shared_ptr(command);
  30. UndoRedo::instance().registerCommand(commandPtr);
  31. commandPtr->commit();
  32. return commandPtr->mSceneObject;
  33. }
  34. void CmdCreateSO::commit()
  35. {
  36. mSceneObject = SceneObject::create(mName, mFlags);
  37. for(auto entry : mComponentTypeIds)
  38. mSceneObject->addComponent(entry);
  39. Selection::instance().setSceneObjects({ mSceneObject });
  40. }
  41. void CmdCreateSO::revert()
  42. {
  43. if (mSceneObject == nullptr)
  44. return;
  45. if (!mSceneObject.isDestroyed())
  46. mSceneObject->destroy(true);
  47. mSceneObject = nullptr;
  48. }
  49. }