From 142f025692a562426c11434d4145f893b9474ec2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 20:54:16 +0800 Subject: [PATCH] Added check for editor camera. --- Assets/Application.SHConfig | 2 +- Assets/Scenes/UI Test.shade | 79 ++++++++++++++++++++++++++++++ Assets/Scenes/UI Test.shade.shmeta | 3 ++ SHADE_Engine/src/UI/SHUISystem.cpp | 19 ++++++- 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 Assets/Scenes/UI Test.shade create mode 100644 Assets/Scenes/UI Test.shade.shmeta diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 3f7a4ac0..c9b34a7a 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 94283040 +Starting Scene ID: 94246101 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade b/Assets/Scenes/UI Test.shade new file mode 100644 index 00000000..b6aab1a1 --- /dev/null +++ b/Assets/Scenes/UI Test.shade @@ -0,0 +1,79 @@ +- EID: 0 + Name: Canvas + IsActive: true + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 10 + Canvas Height: 10 + IsActive: true + Scripts: ~ +- EID: 6 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Scripts: ~ +- EID: 1 + Name: Camera + IsActive: true + NumberOfChildren: 0 + Components: + Camera Component: + Position: {x: 0, y: 3, z: 8} + Pitch: 0 + Yaw: 0 + Roll: 0 + Width: 1920 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + IsActive: true + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Directional + Direction: {x: 1.79999995, y: 0, z: 1} + Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1} + Layer: 4294967295 + Strength: 0 + IsActive: true + Scripts: ~ +- EID: 7 + Name: BigBoi + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -16.8647861, z: -14.039052} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + Scripts: ~ +- EID: 8 + Name: AmbientLight + IsActive: true + NumberOfChildren: 0 + Components: + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Ambient + Direction: {x: 0, y: 0, z: 1} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 0.25 + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta new file mode 100644 index 00000000..0e80f988 --- /dev/null +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -0,0 +1,3 @@ +Name: UI Test +ID: 96139961 +Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index a499a475..247eb6cc 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -7,6 +7,7 @@ #include "Camera/SHCameraSystem.h" #include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h" +#include "Editor/SHEditor.h" #include "Resource/SHResourceManager.h" #include "Input/SHInputManager.h" @@ -118,10 +119,26 @@ namespace SHADE void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept { auto cameraSystem = SHSystemManager::GetSystem(); - +#ifdef SHEDITOR + auto editor = SHSystemManager::GetSystem(); + if (editor->editorState != SHEditor::State::PLAY) + { + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetEditorCamera()->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = cameraSystem->GetEditorCamera()->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); + } + else + { + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); + } + +#else comp.canvasMatrix = SHMatrix::Identity; comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f ); comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f ); +#endif } void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept