Camera locking when its transform is locked (#5996)
* Locking the camera when its entity transform is locked Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Added function to unposses camera when transform locks Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Basic camera behaviour Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com> * Addressed codereview suggestions Signed-off-by: AMZN-Igarri <82394219+AMZN-Igarri@users.noreply.github.com>
This commit is contained in:
@@ -151,7 +151,12 @@ namespace Camera
|
||||
|
||||
void CameraComponentController::SetShouldActivateFunction(AZStd::function<bool()> shouldActivateFunction)
|
||||
{
|
||||
m_shouldActivateFn = shouldActivateFunction;
|
||||
m_shouldActivateFn = AZStd::move(shouldActivateFunction);
|
||||
}
|
||||
|
||||
void CameraComponentController::SetIsLockedFunction(AZStd::function<bool()> isLockedFunction)
|
||||
{
|
||||
m_isLockedFn = AZStd::move(isLockedFunction);
|
||||
}
|
||||
|
||||
void CameraComponentController::Reflect(AZ::ReflectContext* context)
|
||||
@@ -195,10 +200,11 @@ namespace Camera
|
||||
{
|
||||
m_onViewMatrixChanged = AZ::Event<const AZ::Matrix4x4&>::Handler([this](const AZ::Matrix4x4&)
|
||||
{
|
||||
if (!m_updatingTransformFromEntity)
|
||||
if (!m_updatingTransformFromEntity && !m_isLockedFn())
|
||||
{
|
||||
AZ::TransformBus::Event(m_entityId, &AZ::TransformInterface::SetWorldTM, m_atomCamera->GetCameraTransform());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ namespace Camera
|
||||
//! Used by the Editor to disable undesirable camera changes in edit mode.
|
||||
void SetShouldActivateFunction(AZStd::function<bool()> shouldActivateFunction);
|
||||
|
||||
//! Defines a callback for determining whether this camera is currently locked by its transform.
|
||||
void SetIsLockedFunction(AZStd::function<bool()> isLockedFunction);
|
||||
|
||||
// Controller interface
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
||||
@@ -136,5 +139,6 @@ namespace Camera
|
||||
bool m_isActiveView = false;
|
||||
|
||||
AZStd::function<bool()> m_shouldActivateFn;
|
||||
AZStd::function<bool()> m_isLockedFn = []{ return false; };
|
||||
};
|
||||
} // namespace Camera
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <Atom/RPI.Public/ViewportContext.h>
|
||||
#include <Atom/RPI.Public/View.h>
|
||||
#include <AzToolsFramework/ToolsComponents/TransformComponent.h>
|
||||
|
||||
namespace Camera
|
||||
{
|
||||
@@ -41,6 +42,16 @@ namespace Camera
|
||||
return isInGameMode;
|
||||
});
|
||||
|
||||
// Only allow our camera to move when the transform is not locked.
|
||||
m_controller.SetIsLockedFunction([this]()
|
||||
{
|
||||
bool locked = false;
|
||||
AzToolsFramework::Components::TransformComponentMessages::Bus::EventResult(
|
||||
locked, GetEntityId(), &AzToolsFramework::Components::TransformComponentMessages::IsTransformLocked);
|
||||
|
||||
return locked;
|
||||
});
|
||||
|
||||
// Call base class activate, which in turn calls Activate on our controller.
|
||||
EditorCameraComponentBase::Activate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user