EditorRecastNavigationPhysXProviderComponent.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "EditorRecastNavigationPhysXProviderComponent.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. namespace RecastNavigation
  11. {
  12. void EditorRecastNavigationPhysXProviderComponent::Reflect(AZ::ReflectContext* context)
  13. {
  14. BaseClass::Reflect(context);
  15. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  16. {
  17. serializeContext->Class<EditorRecastNavigationPhysXProviderComponent, BaseClass>()
  18. ->Version(1);
  19. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  20. {
  21. editContext->Class<EditorRecastNavigationPhysXProviderComponent>("Recast Navigation PhysX Provider",
  22. "[Collects triangle geometry from PhysX scene for navigation mesh within the area defined by a shape component.]")
  23. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  24. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  25. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  26. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  27. ;
  28. editContext->Class<RecastNavigationPhysXProviderComponentController>(
  29. "RecastNavigationPhysXProviderComponentController", "")
  30. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  31. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  32. ->DataElement(AZ::Edit::UIHandlers::Default, &RecastNavigationPhysXProviderComponentController::m_config, "Configuration", "")
  33. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  34. ;
  35. editContext->Class<RecastNavigationPhysXProviderConfig>("Recast Navigation PhysX Provider Config",
  36. "[Navigation PhysX Provider configuration]")
  37. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  38. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  39. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  40. ->DataElement(AZ::Edit::UIHandlers::Default, &RecastNavigationPhysXProviderConfig::m_collisionGroupId, "Collision Group",
  41. "If set, only colliders from the specified collision group will be considered.")
  42. ;
  43. }
  44. }
  45. }
  46. EditorRecastNavigationPhysXProviderComponent::EditorRecastNavigationPhysXProviderComponent(const RecastNavigationPhysXProviderConfig& config)
  47. : BaseClass(config)
  48. {
  49. }
  50. void EditorRecastNavigationPhysXProviderComponent::Activate()
  51. {
  52. m_controller.m_config.m_useEditorScene = true;
  53. BaseClass::Activate();
  54. }
  55. void EditorRecastNavigationPhysXProviderComponent::Deactivate()
  56. {
  57. BaseClass::Deactivate();
  58. }
  59. void EditorRecastNavigationPhysXProviderComponent::BuildGameEntity(AZ::Entity* gameEntity)
  60. {
  61. m_controller.m_config.m_useEditorScene = false;
  62. // The game entity must query the regular game PhysX scene, while the Editor component must query the Editor PhysX scene.
  63. BaseClass::BuildGameEntity(gameEntity);
  64. m_controller.m_config.m_useEditorScene = true;
  65. }
  66. AZ::u32 EditorRecastNavigationPhysXProviderComponent::OnConfigurationChanged()
  67. {
  68. m_controller.OnConfigurationChanged();
  69. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  70. }
  71. } // namespace RecastNavigation