EditorDebugDrawLineComponent.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 "EditorDebugDrawLineComponent.h"
  11. namespace DebugDraw
  12. {
  13. void EditorDebugDrawLineComponent::Reflect(AZ::ReflectContext* context)
  14. {
  15. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  16. if (serializeContext)
  17. {
  18. serializeContext->Class<EditorDebugDrawLineComponent, EditorComponentBase>()
  19. ->Version(0)
  20. ->Field("Element", &EditorDebugDrawLineComponent::m_element)
  21. ->Field("Settings", &EditorDebugDrawLineComponent::m_settings)
  22. ;
  23. AZ::EditContext* editContext = serializeContext->GetEditContext();
  24. if (editContext)
  25. {
  26. editContext->Class<EditorDebugDrawLineComponent>(
  27. "DebugDraw Line", "Draws debug line 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/DebugDrawLine.svg")
  31. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/DebugDrawLine.svg")
  32. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  33. ->DataElement(0, &EditorDebugDrawLineComponent::m_element, "Line element settings", "Settings for the line element.")
  34. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDebugDrawLineComponent::OnPropertyUpdate)
  35. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  36. ->DataElement(0, &EditorDebugDrawLineComponent::m_settings, "Visibility settings", "Common settings for DebugDraw components.")
  37. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDebugDrawLineComponent::OnPropertyUpdate)
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ;
  40. }
  41. }
  42. }
  43. void EditorDebugDrawLineComponent::BuildGameEntity(AZ::Entity* gameEntity)
  44. {
  45. if (m_settings.m_visibleInGame)
  46. {
  47. gameEntity->CreateComponent<DebugDrawLineComponent>(m_element);
  48. }
  49. }
  50. void EditorDebugDrawLineComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  51. {
  52. DebugDrawLineComponent::GetProvidedServices(provided);
  53. }
  54. void EditorDebugDrawLineComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  55. {
  56. DebugDrawLineComponent::GetIncompatibleServices(incompatible);
  57. }
  58. void EditorDebugDrawLineComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  59. {
  60. DebugDrawLineComponent::GetRequiredServices(required);
  61. }
  62. void EditorDebugDrawLineComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  63. {
  64. DebugDrawLineComponent::GetDependentServices(dependent);
  65. }
  66. void EditorDebugDrawLineComponent::Init()
  67. {
  68. m_element.m_owningEditorComponent = GetId();
  69. }
  70. void EditorDebugDrawLineComponent::Activate()
  71. {
  72. if (m_settings.m_visibleInEditor)
  73. {
  74. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::RegisterDebugDrawComponent, this);
  75. }
  76. }
  77. void EditorDebugDrawLineComponent::Deactivate()
  78. {
  79. DebugDrawInternalRequestBus::Broadcast(&DebugDrawInternalRequestBus::Events::UnregisterDebugDrawComponent, this);
  80. }
  81. void EditorDebugDrawLineComponent::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