AudioSwitchComponent.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/string/string.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <LmbrCentral/Audio/AudioSwitchComponentBus.h>
  12. #include <IAudioInterfacesCommonData.h>
  13. namespace LmbrCentral
  14. {
  15. /*!
  16. * AudioSwitchComponent
  17. * A 'Switch' is something that can be in one 'State' at a time, but "switched" at run-time.
  18. * For example, a Switch called 'SurfaceMaterial' might have States such as 'Grass', 'Snow', 'Metal', 'Wood'.
  19. * But a Footstep sound would only be in one of those States at a time.
  20. */
  21. class AudioSwitchComponent
  22. : public AZ::Component
  23. , public AudioSwitchComponentRequestBus::Handler
  24. {
  25. public:
  26. /*!
  27. * AZ::Component
  28. */
  29. AZ_COMPONENT(AudioSwitchComponent, "{85FD9037-A5EA-4783-B49A-7959BBB34011}");
  30. void Activate() override;
  31. void Deactivate() override;
  32. AudioSwitchComponent() = default;
  33. AudioSwitchComponent(const AZStd::string& switchName, const AZStd::string& stateName);
  34. /*!
  35. * AudioSwitchComponentRequestBus::Handler Interface
  36. */
  37. void SetState(const char* stateName) override;
  38. void SetSwitchState(const char* switchName, const char* stateName) override;
  39. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  40. {
  41. provided.push_back(AZ_CRC_CE("AudioSwitchService"));
  42. }
  43. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  44. {
  45. required.push_back(AZ_CRC_CE("AudioProxyService"));
  46. }
  47. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  48. {
  49. dependent.push_back(AZ_CRC_CE("AudioPreloadService"));
  50. }
  51. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  52. {
  53. incompatible.push_back(AZ_CRC_CE("AudioSwitchService"));
  54. }
  55. static void Reflect(AZ::ReflectContext* context);
  56. private:
  57. //! Editor callbacks
  58. void OnDefaultSwitchChanged();
  59. void OnDefaultStateChanged();
  60. //! Transient data
  61. Audio::TAudioControlID m_defaultSwitchID;
  62. Audio::TAudioControlID m_defaultStateID;
  63. //! Serialized data
  64. AZStd::string m_defaultSwitchName;
  65. AZStd::string m_defaultStateName;
  66. };
  67. }