Fix for Canvas Scaler #253
|
@ -22,6 +22,11 @@
|
||||||
Mesh: 141771688
|
Mesh: 141771688
|
||||||
Material: 129340704
|
Material: 129340704
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
Button Component:
|
||||||
|
Default Texture: 0
|
||||||
|
Hovered Texture: 0
|
||||||
|
Clicked Texture: 0
|
||||||
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 1
|
- EID: 1
|
||||||
Name: Camera
|
Name: Camera
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
Name: UI Test
|
Name: UI Test
|
||||||
ID: 96139961
|
ID: 87707373
|
||||||
Type: 5
|
Type: 5
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "Math/Transform/SHTransformComponent.h"
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "Scene/SHSceneManager.h"
|
#include "Scene/SHSceneManager.h"
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
#include "Editor/SHEditor.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -440,4 +442,22 @@ namespace SHADE
|
||||||
SetCameraViewMatrix(camera, viewMtx);
|
SetCameraViewMatrix(camera, viewMtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept
|
||||||
|
{
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
auto editor = SHSystemManager::GetSystem<SHEditor>();
|
||||||
|
if (editor->editorState != SHEditor::State::PLAY)
|
||||||
|
{
|
||||||
|
return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetHeight() };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace SHADE
|
||||||
void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept;
|
void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHCameraSystem(void) = default;
|
SHCameraSystem(void) = default;
|
||||||
virtual ~SHCameraSystem(void) = default;
|
virtual ~SHCameraSystem(void) = default;
|
||||||
|
@ -57,6 +58,8 @@ namespace SHADE
|
||||||
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept;
|
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept;
|
||||||
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
|
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
|
||||||
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;
|
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;
|
||||||
|
|
||||||
|
SHVec2 GetCameraWidthHeight(size_t index) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -119,26 +119,10 @@ namespace SHADE
|
||||||
void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept
|
void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept
|
||||||
{
|
{
|
||||||
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||||
#ifdef SHEDITOR
|
SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0);
|
||||||
auto editor = SHSystemManager::GetSystem<SHEditor>();
|
|
||||||
if (editor->editorState != SHEditor::State::PLAY)
|
|
||||||
{
|
|
||||||
comp.canvasMatrix = SHMatrix::Identity;
|
comp.canvasMatrix = SHMatrix::Identity;
|
||||||
comp.canvasMatrix(0, 0) = cameraSystem->GetEditorCamera()->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f);
|
comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f);
|
||||||
comp.canvasMatrix(1, 1) = cameraSystem->GetEditorCamera()->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f);
|
comp.canvasMatrix(1, 1) = camSize.y * 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
|
void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept
|
||||||
|
@ -183,7 +167,7 @@ namespace SHADE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SHVec2 camSize{ cameraSystem->GetDirector(0)->GetWidth() , cameraSystem->GetDirector(0)->GetHeight() };
|
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y };
|
||||||
|
|
||||||
topExtent += camSize * 0.5f;
|
topExtent += camSize * 0.5f;
|
||||||
btmExtent += camSize * 0.5f;
|
btmExtent += camSize * 0.5f;
|
||||||
|
|
Loading…
Reference in New Issue