EditorDiskShapeComponent.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "DiskShapeComponent.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include "EditorDiskShapeComponent.h"
  11. #include "EditorShapeComponentConverters.h"
  12. #include "ShapeDisplay.h"
  13. namespace LmbrCentral
  14. {
  15. void EditorDiskShapeComponent::Reflect(AZ::ReflectContext* context)
  16. {
  17. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<EditorDiskShapeComponent, EditorBaseShapeComponent>()
  20. ->Version(1)
  21. ->Field("DiskShape", &EditorDiskShapeComponent::m_diskShape)
  22. ;
  23. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  24. {
  25. editContext->Class<EditorDiskShapeComponent>(
  26. "Disk Shape", "The Disk Shape component creates a disk around the associated entity")
  27. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  28. ->Attribute(AZ::Edit::Attributes::Category, "Shape")
  29. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Disk_Shape.svg")
  30. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Disk_Shape.svg")
  31. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  32. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  33. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.o3de.org/docs/user-guide/components/reference/shape/disk-shape/")
  34. ->DataElement(AZ::Edit::UIHandlers::Default, &EditorDiskShapeComponent::m_diskShape, "Disk Shape", "Disk Shape Configuration")
  35. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorDiskShapeComponent::ConfigurationChanged)
  36. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  37. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  38. ;
  39. }
  40. }
  41. }
  42. void EditorDiskShapeComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  43. {
  44. EditorBaseShapeComponent::GetProvidedServices(provided);
  45. provided.push_back(AZ_CRC_CE("DiskShapeService"));
  46. }
  47. void EditorDiskShapeComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  48. {
  49. EditorBaseShapeComponent::GetIncompatibleServices(incompatible);
  50. incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
  51. }
  52. void EditorDiskShapeComponent::Init()
  53. {
  54. EditorBaseShapeComponent::Init();
  55. SetShapeComponentConfig(&m_diskShape.ModifyShapeComponent());
  56. }
  57. void EditorDiskShapeComponent::Activate()
  58. {
  59. EditorBaseShapeComponent::Activate();
  60. m_diskShape.Activate(GetEntityId());
  61. AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId());
  62. }
  63. void EditorDiskShapeComponent::Deactivate()
  64. {
  65. AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();
  66. m_diskShape.Deactivate();
  67. EditorBaseShapeComponent::Deactivate();
  68. }
  69. void EditorDiskShapeComponent::DisplayEntityViewport(
  70. [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo,
  71. AzFramework::DebugDisplayRequests& debugDisplay)
  72. {
  73. DisplayShape(
  74. debugDisplay, [this]() { return CanDraw(); },
  75. [this](AzFramework::DebugDisplayRequests& debugDisplay)
  76. {
  77. DrawDiskShape(
  78. { m_diskShape.GetDiskConfiguration().GetDrawColor(), m_shapeWireColor, m_displayFilled },
  79. m_diskShape.GetDiskConfiguration(), debugDisplay);
  80. },
  81. m_diskShape.GetCurrentTransform());
  82. }
  83. void EditorDiskShapeComponent::ConfigurationChanged()
  84. {
  85. m_diskShape.InvalidateCache(InvalidateShapeCacheReason::ShapeChange);
  86. ShapeComponentNotificationsBus::Event(
  87. GetEntityId(), &ShapeComponentNotificationsBus::Events::OnShapeChanged,
  88. ShapeComponentNotifications::ShapeChangeReasons::ShapeChanged);
  89. }
  90. void EditorDiskShapeComponent::BuildGameEntity(AZ::Entity* gameEntity)
  91. {
  92. if (auto component = gameEntity->CreateComponent<DiskShapeComponent>())
  93. {
  94. component->SetConfiguration(m_diskShape.GetDiskConfiguration());
  95. }
  96. if (m_visibleInGameView)
  97. {
  98. if (auto component = gameEntity->CreateComponent<DiskShapeDebugDisplayComponent>())
  99. {
  100. component->SetConfiguration(m_diskShape.GetDiskConfiguration());
  101. }
  102. }
  103. }
  104. } // namespace LmbrCentral