DetourNavigationComponent.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <RecastNavigation/DetourNavigationBus.h>
  11. namespace RecastNavigation
  12. {
  13. //! Calculates paths over the associated navigation mesh.
  14. //! Provides APIs to find a path between two entities or two world positions.
  15. class DetourNavigationComponent final
  16. : public AZ::Component
  17. , public DetourNavigationRequestBus::Handler
  18. {
  19. public:
  20. AZ_COMPONENT(DetourNavigationComponent, "{B9A8F260-2772-4C94-8DE4-850C94A8F2AC}");
  21. DetourNavigationComponent() = default;
  22. //! Constructor to be used by Editor variant to pass the configuration in.
  23. //! @param navQueryEntityId entity id of the entity with a navigation mesh component.
  24. //! @param nearestDistance distance to use when finding nearest point on the navigation
  25. //! mesh when points provided to FindPath are outside of the navigation mesh.
  26. DetourNavigationComponent(AZ::EntityId navQueryEntityId, float nearestDistance);
  27. static void Reflect(AZ::ReflectContext* context);
  28. //! DetourNavigationRequestBus overrides ...
  29. //! @{
  30. AZStd::vector<AZ::Vector3> FindPathBetweenEntities(AZ::EntityId fromEntity, AZ::EntityId toEntity) override;
  31. AZStd::vector<AZ::Vector3> FindPathBetweenPositions(const AZ::Vector3& fromWorldPosition, const AZ::Vector3& toWorldPosition) override;
  32. void SetNavigationMeshEntity(AZ::EntityId navMeshEntity) override;
  33. AZ::EntityId GetNavigationMeshEntity() const override;
  34. //! @}
  35. //! AZ::Component overrides ...
  36. //! @{
  37. void Activate() override;
  38. void Deactivate() override;
  39. //! @}
  40. private:
  41. //! Entity id of the entity with a navigation mesh component.
  42. AZ::EntityId m_navQueryEntityId;
  43. //! Distance to use when finding nearest point on the navigation mesh when points provided to FindPath are outside of the navigation mesh.
  44. float m_nearestDistance = 3.f;
  45. };
  46. } // namespace RecastNavigation