AudioProxyComponent.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/std/containers/map.h>
  10. #include <AzCore/Math/Transform.h>
  11. #include <AzCore/Component/Component.h>
  12. #include <AzCore/Component/TransformBus.h>
  13. #include <LmbrCentral/Audio/AudioProxyComponentBus.h>
  14. namespace LmbrCentral
  15. {
  16. /*!
  17. * AudioProxyComponent
  18. * A component wrapper for an AudioProxy,
  19. * which acts as a proxy for a logical Audio Object.
  20. * ATL components 'share' the AudioProxyComponent on an Entity.
  21. * There is only 1 AudioProxyComponent allowed on an Entity.
  22. */
  23. class AudioProxyComponent
  24. : public AZ::Component
  25. , public AZ::TransformNotificationBus::Handler
  26. , public AudioProxyComponentRequestBus::Handler
  27. {
  28. public:
  29. /*!
  30. * AZ::Component
  31. */
  32. AZ_COMPONENT(AudioProxyComponent, "{0EE6EE0F-7939-4AB8-B0E3-F9B3925D61EE}");
  33. void Activate() override;
  34. void Deactivate() override;
  35. /*!
  36. * AZ::TransformNotificationBus::Handler
  37. * Required Interface
  38. */
  39. void OnTransformChanged(const AZ::Transform&, const AZ::Transform&) override;
  40. /*!
  41. * AudioProxyComponentRequestBus::Handler
  42. * Required Interface
  43. */
  44. bool ExecuteTrigger(
  45. const Audio::TAudioControlID triggerID
  46. ) override;
  47. bool ExecuteSourceTrigger(
  48. const Audio::TAudioControlID triggerID,
  49. const Audio::SAudioSourceInfo& sourceInfo
  50. ) override;
  51. void KillTrigger(const Audio::TAudioControlID triggerID) override;
  52. void KillAllTriggers() override;
  53. void SetRtpcValue(const Audio::TAudioControlID rtpcID, float value) override;
  54. void SetSwitchState(const Audio::TAudioControlID switchID, const Audio::TAudioSwitchStateID stateID) override;
  55. void SetEnvironmentAmount(const Audio::TAudioEnvironmentID environmentID, float amount) override;
  56. void SetMovesWithEntity(bool shouldTrackEntity) override
  57. {
  58. m_tracksEntityPosition = shouldTrackEntity;
  59. }
  60. void SetObstructionCalcType(const Audio::ObstructionType type) override;
  61. void SetPosition(const Audio::SATLWorldPosition& position) override;
  62. void SetMultiplePositions(const Audio::MultiPositionParams& params) override;
  63. protected:
  64. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  65. {
  66. provided.push_back(AZ_CRC_CE("AudioProxyService"));
  67. }
  68. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  69. {
  70. required.push_back(AZ_CRC_CE("TransformService"));
  71. }
  72. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  73. {
  74. incompatible.push_back(AZ_CRC_CE("AudioProxyService"));
  75. }
  76. static void Reflect(AZ::ReflectContext* context);
  77. private:
  78. //! Transient data
  79. Audio::IAudioProxy* m_audioProxy = nullptr;
  80. bool m_tracksEntityPosition = true;
  81. AZ::Transform m_transform;
  82. //! Serialized data
  83. // None! The AudioProxyComponent, by design, is completely transient.
  84. };
  85. } // namespace LmbrCentral