AudioAreaEnvironmentComponent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <AzCore/Component/TransformBus.h>
  11. #include <AzFramework/Physics/RigidBodyBus.h>
  12. #include <AzFramework/Physics/Common/PhysicsSimulatedBodyEvents.h>
  13. #include <IAudioSystem.h>
  14. namespace LmbrCentral
  15. {
  16. /*!
  17. * AudioAreaEnvironmentComponent
  18. * This component contains an Entity reference which should link to an Entity
  19. * that has a TriggerAreaComponent or PhysX Collider with Trigger enabled. That Trigger Area (and shape) will act as the
  20. * broad-phase trigger. Once Entities go inside, this component will track their
  21. * movement until they leave the Trigger Area.
  22. * The AudioAreaEnvironmentComponent's Entity requires it's own Shape that defines
  23. * where the Environment is fully applied. This shape should be placed interior
  24. * to the Trigger Area. Entities that are between the two shapes will 'fade'
  25. * the environment amount based on the Environment fade distance property.
  26. */
  27. class AudioAreaEnvironmentComponent
  28. : public AZ::Component
  29. , protected Physics::RigidBodyNotificationBus::Handler
  30. , private AZ::TransformNotificationBus::MultiHandler
  31. {
  32. friend class EditorAudioAreaEnvironmentComponent;
  33. public:
  34. AudioAreaEnvironmentComponent();
  35. /*!
  36. * AZ::Component
  37. */
  38. AZ_COMPONENT(AudioAreaEnvironmentComponent, "{52300012-FFCD-4559-9479-20F463940320}");
  39. void Activate() override;
  40. void Deactivate() override;
  41. /*!
  42. * AZ::TransformNotificationBus::MultiHandler
  43. */
  44. void OnTransformChanged(const AZ::Transform&, const AZ::Transform&) override;
  45. protected:
  46. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  47. {
  48. provided.push_back(AZ_CRC_CE("AudioAreaEnvironmentService"));
  49. }
  50. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  51. {
  52. dependent.push_back(AZ_CRC_CE("AudioPreloadService"));
  53. }
  54. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  55. {
  56. required.push_back(AZ_CRC_CE("ShapeService"));
  57. }
  58. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  59. {
  60. incompatible.push_back(AZ_CRC_CE("AudioAreaEnvironmentService"));
  61. }
  62. static void Reflect(AZ::ReflectContext* context);
  63. // Physics::RigidBodyNotifications overrides ...
  64. void OnPhysicsEnabled(const AZ::EntityId& entityId) override;
  65. void OnPhysicsDisabled(const AZ::EntityId& entityId) override;
  66. private:
  67. void OnTriggerEnter(const AzPhysics::TriggerEvent& triggerEvent);
  68. void OnTriggerExit(const AzPhysics::TriggerEvent& triggerEvent);
  69. AzPhysics::SimulatedBodyEvents::OnTriggerEnter::Handler m_onTriggerEnterHandler;
  70. AzPhysics::SimulatedBodyEvents::OnTriggerExit::Handler m_onTriggerExitHandler;
  71. //! Transient data
  72. Audio::TAudioEnvironmentID m_environmentId;
  73. //! Serialized data
  74. AZ::EntityId m_broadPhaseTriggerArea;
  75. AZStd::string m_environmentName;
  76. float m_environmentFadeDistance = 1.f;
  77. };
  78. } // namespace LmbrCentral