ROS2SpawnPointComponent.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "ROS2SpawnPointComponent.h"
  9. #include <AzCore/Component/Entity.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/Serialization/EditContextConstants.inl>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <AzFramework/Components/TransformComponent.h>
  14. namespace ROS2
  15. {
  16. void ROS2SpawnPointComponent::Activate()
  17. {
  18. }
  19. void ROS2SpawnPointComponent::Deactivate()
  20. {
  21. }
  22. void ROS2SpawnPointComponent::Reflect(AZ::ReflectContext* context)
  23. {
  24. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  25. {
  26. serialize->Class<ROS2SpawnPointComponent, AZ::Component>()
  27. ->Version(1)
  28. ->Field("Name", &ROS2SpawnPointComponent::m_name)
  29. ->Field("Info", &ROS2SpawnPointComponent::m_info);
  30. if (AZ::EditContext* ec = serialize->GetEditContext())
  31. {
  32. ec->Class<ROS2SpawnPointComponent>("ROS2 Spawn Point", "Spawn Point")
  33. ->ClassElement(AZ::Edit::ClassElements::EditorData, "Stores information about available spawn point")
  34. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  35. ->Attribute(AZ::Edit::Attributes::Category, "ROS2")
  36. ->DataElement(AZ::Edit::UIHandlers::EntityId, &ROS2SpawnPointComponent::m_name, "Name", "Name")
  37. ->DataElement(
  38. AZ::Edit::UIHandlers::EntityId, &ROS2SpawnPointComponent::m_info, "Info", "Spawn point detailed description");
  39. }
  40. }
  41. }
  42. AZStd::pair<AZStd::string, SpawnPointInfo> ROS2SpawnPointComponent::GetInfo() const
  43. {
  44. auto transform_component = GetEntity()->FindComponent<AzFramework::TransformComponent>();
  45. // if SpawnPointComponent entity for some reason does not include TransformComponent - this default pose will be returned
  46. AZ::Transform transform = { AZ::Vector3{ 0, 0, 0 }, AZ::Quaternion{ 0, 0, 0, 1.0 }, 1.0 };
  47. if (transform_component != nullptr)
  48. {
  49. transform = transform_component->GetWorldTM();
  50. }
  51. return { m_name, SpawnPointInfo{ m_info, transform } };
  52. }
  53. } // namespace ROS2