EntityDebugDisplayComponent.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EntityDebugDisplayComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <Shape/ShapeDisplay.h>
  11. namespace LmbrCentral
  12. {
  13. void EntityDebugDisplayComponent::Activate()
  14. {
  15. m_currentEntityTransform = AZ::Transform::CreateIdentity();
  16. AZ::TransformBus::EventResult(m_currentEntityTransform, GetEntityId(), &AZ::TransformInterface::GetWorldTM);
  17. AZ::TransformNotificationBus::Handler::BusConnect(GetEntityId());
  18. AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId());
  19. }
  20. void EntityDebugDisplayComponent::Deactivate()
  21. {
  22. AZ::TransformNotificationBus::Handler::BusDisconnect();
  23. AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();
  24. }
  25. void EntityDebugDisplayComponent::OnTransformChanged(const AZ::Transform& /*local*/, const AZ::Transform& world)
  26. {
  27. m_currentEntityTransform = world;
  28. }
  29. void EntityDebugDisplayComponent::DisplayEntityViewport(
  30. [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo,
  31. AzFramework::DebugDisplayRequests& debugDisplay)
  32. {
  33. DisplayShape(
  34. debugDisplay,
  35. []() { return true; }, // canDraw function - in game mode/view we always want to draw, so just return true
  36. [this](AzFramework::DebugDisplayRequests& debugDisplay)
  37. {
  38. Draw(debugDisplay);
  39. },
  40. m_currentEntityTransform);
  41. }
  42. void EntityDebugDisplayComponent::Reflect(AZ::ReflectContext* context)
  43. {
  44. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  45. {
  46. serializeContext->Class<EntityDebugDisplayComponent, AZ::Component>()
  47. ->Version(1);
  48. }
  49. }
  50. }