EditorDebugDrawObbComponent.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include "EditorDebugDrawObbComponent.h"
  11. namespace DebugDraw
  12. {
  13. void EditorDebugDrawObbComponent::Reflect(AZ::ReflectContext* context)
  14. {
  15. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  16. if (serializeContext)
  17. {
  18. serializeContext->Class<EditorDebugDrawObbComponent, EditorComponentBase>()
  19. ->Version(0)
  20. ->Field("Element", &EditorDebugDrawObbComponent::m_element)
  21. ->Field("Settings", &EditorDebugDrawObbComponent::m_settings)
  22. ;
  23. AZ::EditContext* editContext = serializeContext->GetEditContext();
  24. if (editContext)
  25. {
  26. editContext->Class<EditorDebugDrawObbComponent>(
  27. "DebugDraw Obb", "Draws debug obb on the screen from this entity's location to specified end entity's location.")
  28. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  29. ->Attribute(AZ::Edit::Attributes::Category, "Debugging")
  30. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/DebugDrawObb.svg")
  31. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/DebugDrawObb.svg")
  32. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
  33. ->DataElement(0, &EditorDebugDrawObbComponent::m_element, "Obb element settings", "Settings for the obb element.")
  34. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDebugDrawObbComponent::OnPropertyUpdate)
  35. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  36. ->DataElement(0, &EditorDebugDrawObbComponent::m_settings, "Visibility settings", "Common settings for DebugDraw components.")
  37. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDebugDrawObbComponent::OnPropertyUpdate)
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ;
  40. }
  41. }
  42. }
  43. void EditorDebugDrawObbComponent::BuildGameEntity(AZ::Entity* gameEntity)
  44. {
  45. if (m_settings.m_visibleInGame)
  46. {
  47. gameEntity->CreateComponent<DebugDrawObbComponent>(m_element);
  48. }
  49. }
  50. void EditorDebugDrawObbComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  51. {
  52. DebugDrawObbComponent::GetProvidedServices(provided);
  53. }
  54. void EditorDebugDrawObbComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  55. {
  56. DebugDrawObbComponent::GetIncompatibleServices(incompatible);
  57. }
  58. void EditorDebugDrawObbComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  59. {
  60. DebugDrawObbComponent::GetRequiredServices(required);
  61. }
  62. void EditorDebugDrawObbComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  63. {
  64. DebugDrawObbComponent::GetDependentServices(dependent);
  65. }
  66. void EditorDebugDrawObbComponent::Init()
  67. {
  68. m_element.m_owningEditorComponent = GetId();
  69. }
  70. void EditorDebugDrawObbComponent::Activate()
  71. {
  72. if (m_settings.m_visibleInEditor)
  73. {
  74. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::RegisterDebugDrawComponent, this);
  75. }
  76. }
  77. void EditorDebugDrawObbComponent::Deactivate()
  78. {
  79. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::UnregisterDebugDrawComponent, this);
  80. }
  81. void EditorDebugDrawObbComponent::OnPropertyUpdate()
  82. {
  83. // Property updated, we need to update the system component (which handles drawing the components) with our new info
  84. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::UnregisterDebugDrawComponent, this);
  85. if (m_settings.m_visibleInEditor)
  86. {
  87. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::RegisterDebugDrawComponent, this);
  88. }
  89. }
  90. } // namespace DebugDraw