-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransformEditorCommand.cpp
More file actions
45 lines (37 loc) · 1.08 KB
/
Copy pathTransformEditorCommand.cpp
File metadata and controls
45 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "Editor/TransformEditorCommand.h"
#include "AssetDatabase.h"
#include "Core/Reflection.hpp"
#include "Core/SObjectManager.h"
#include "Game/GameObject.h"
namespace sh::editor
{
TransformEditorCommand::TransformEditorCommand(const core::UUID& objectUUID, std::string name, Snapshot before, Snapshot after) :
objectUUID(objectUUID),
name(std::move(name)),
before(std::move(before)),
after(std::move(after))
{
}
SH_EDITOR_API void TransformEditorCommand::Execute()
{
Apply(after);
}
SH_EDITOR_API void TransformEditorCommand::Undo()
{
Apply(before);
}
SH_EDITOR_API auto TransformEditorCommand::GetName() const -> std::string_view
{
return name;
}
void TransformEditorCommand::Apply(const Snapshot& snapshot) const
{
auto* sobj = core::SObjectManager::GetInstance()->GetSObject(objectUUID);
auto* obj = core::reflection::Cast<game::GameObject>(sobj);
if (!core::IsValid(obj))
return;
obj->transform->SetWorldPosition(snapshot.position);
obj->transform->SetWorldRotation(snapshot.rotation);
obj->transform->SetScale(snapshot.scale);
}
}//namespace