forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorWorld.cpp
More file actions
119 lines (104 loc) · 3.63 KB
/
Copy pathEditorWorld.cpp
File metadata and controls
119 lines (104 loc) · 3.63 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "Game/PCH.h"
#include "EditorWorld.h"
#include "EditorResource.h"
#include "EditorUI.h"
#include "Game/GameObject.h"
#include "Game/Component/MeshRenderer.h"
#include "Game/Component/EditorCamera.h"
#include "Game/Component/PickingCamera.h"
#include "Game/Component/PickingRenderer.h"
#include "Game/Component/EditorControl.h"
#include "Game/Component/LineRenderer.h"
namespace sh::editor
{
SH_EDITOR_API EditorWorld::EditorWorld(render::Renderer& renderer, const game::ComponentModule& module, game::ImGUImpl& guiContext) :
World(renderer, module), guiContext(guiContext)
{
game::GameObject* camObj = AddGameObject("EditorCamera");
camObj->transform->SetPosition({ 2.f, 2.f, 2.f });
camObj->hideInspector = true;
editorCamera = camObj->AddComponent<game::EditorCamera>();
editorCamera->SetUUID(core::UUID{ "61b7bc9f9fd2ca27dcbad8106745f62a" });
this->SetMainCamera(editorCamera);
auto PickingCamObj = AddGameObject("PickingCamera");
PickingCamObj->transform->SetParent(camObj->transform);
auto pickingCam = PickingCamObj->AddComponent<game::PickingCamera>();
pickingCam->SetUUID(core::UUID{ "af9cac824334bcaccd86aad8a18e3cba" });
pickingCam->SetFollowCamera(editorCamera);
}
SH_EDITOR_API EditorWorld::~EditorWorld()
{
}
SH_EDITOR_API void EditorWorld::Clean()
{
Super::Clean();
editorUI.reset();
selected = nullptr;
}
SH_EDITOR_API void EditorWorld::SetSelectedObject(core::SObject* obj)
{
if (core::IsValid(selected) && selected->GetType() == game::GameObject::GetStaticType())
{
if (core::IsValid(selected))
{
auto control = static_cast<game::GameObject*>(selected)->GetComponent<game::EditorControl>();
if (core::IsValid(control))
control->Destroy();
}
}
selected = obj;
if (core::IsValid(selected) && selected->GetType() == game::GameObject::GetStaticType())
{
if (static_cast<game::GameObject*>(selected)->GetComponent<game::EditorControl>() == nullptr)
{
auto control = static_cast<game::GameObject*>(selected)->AddComponent<game::EditorControl>();
control->SetCamera(editorCamera);
control->hideInspector = true;
}
}
}
SH_EDITOR_API auto EditorWorld::GetSelectedObject() const -> core::SObject*
{
return selected;
}
SH_EDITOR_API void EditorWorld::Start()
{
EditorResource::GetInstance()->LoadAllAssets(*this);
editorUI = std::make_unique<editor::EditorUI>(*this, guiContext);
this->GetMainCamera()->SetRenderTexture(editorUI->GetViewport().GetRenderTexture());
auto grid = this->AddGameObject("Grid");
grid->hideInspector = true;
auto meshRenderer = grid->AddComponent<game::MeshRenderer>();
meshRenderer->SetMesh(this->meshes.GetResource("GridMesh"));
meshRenderer->SetMaterial(this->materials.GetResource("GridMaterial"));
auto axis = AddGameObject("_Axis");
axis->transform->SetPosition(0.f, 0.01f, 0.f);
axis->transform->SetParent(grid->transform);
auto line = axis->AddComponent<game::LineRenderer>();
line->SetEnd({ 10.f, 0.f, 0.f });
line->SetColor({ 1.f, 0.f, 0.f, 1.f });
line = axis->AddComponent<game::LineRenderer>();
line->SetEnd({ 0.f, 10.f, 0.f });
line->SetColor({ 0.f, 1.f, 0.f, 1.f });
line = axis->AddComponent<game::LineRenderer>();
line->SetEnd({ 0.f, 0.f, 10.f });
line->SetColor({ 0.f, 0.f, 1.f, 1.f });
Super::Start();
}
SH_EDITOR_API void EditorWorld::Update(float deltaTime)
{
guiContext.Begin();
editorUI->Update();
editorUI->Render();
guiContext.End();
Super::Update(deltaTime);
}
SH_EDITOR_API auto EditorWorld::Serialize() const -> core::Json
{
return Super::Serialize();
}
SH_EDITOR_API void EditorWorld::Deserialize(const core::Json& json)
{
Super::Deserialize(json);
}
}