EditorAudioTriggerComponent.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "EditorAudioTriggerComponent.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. namespace LmbrCentral
  12. {
  13. //=========================================================================
  14. void EditorAudioTriggerComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  17. if (serializeContext)
  18. {
  19. serializeContext->Class<EditorAudioTriggerComponent, EditorComponentBase>()
  20. ->Version(2)
  21. ->Field("Play Trigger", &EditorAudioTriggerComponent::m_defaultPlayTrigger)
  22. ->Field("Stop Trigger", &EditorAudioTriggerComponent::m_defaultStopTrigger)
  23. ->Field("Obstruction Type", &EditorAudioTriggerComponent::m_obstructionType)
  24. ->Field("Plays Immediately", &EditorAudioTriggerComponent::m_playsImmediately)
  25. ;
  26. serializeContext->Enum<Audio::ObstructionType>()
  27. ->Value("Ignore", Audio::ObstructionType::Ignore)
  28. ->Value("SingleRay", Audio::ObstructionType::SingleRay)
  29. ->Value("MultiRay", Audio::ObstructionType::MultiRay)
  30. ;
  31. if (auto editContext = serializeContext->GetEditContext())
  32. {
  33. editContext->Enum<Audio::ObstructionType>("Obstruction Type", "The types of ray-casts available for obstruction and occlusion")
  34. ->Value("Ignore", Audio::ObstructionType::Ignore)
  35. ->Value("SingleRay", Audio::ObstructionType::SingleRay)
  36. ->Value("MultiRay", Audio::ObstructionType::MultiRay)
  37. ;
  38. editContext->Class<EditorAudioTriggerComponent>("Audio Trigger", "The Audio Trigger component provides Audio Translation Layer (ATL) triggers for play/stop functionality and on-demand execution")
  39. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  40. ->Attribute(AZ::Edit::Attributes::Category, "Audio")
  41. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/AudioTrigger.svg")
  42. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/AudioTrigger.svg")
  43. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  44. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  45. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/audio/trigger/")
  46. ->DataElement("AudioControl", &EditorAudioTriggerComponent::m_defaultPlayTrigger, "Default 'play' Trigger", "The default ATL Trigger control used by 'Play'")
  47. ->DataElement("AudioControl", &EditorAudioTriggerComponent::m_defaultStopTrigger, "Default 'stop' Trigger", "The default ATL Trigger control used by 'Stop'")
  48. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &EditorAudioTriggerComponent::m_obstructionType, "Obstruction Type", "Ray-casts used in calculation of obstruction and occlusion")
  49. ->DataElement(AZ::Edit::UIHandlers::Default, &EditorAudioTriggerComponent::m_playsImmediately, "Plays immediately", "Play when this component is Activated")
  50. ;
  51. }
  52. }
  53. }
  54. //=========================================================================
  55. EditorAudioTriggerComponent::EditorAudioTriggerComponent()
  56. {
  57. m_defaultPlayTrigger.m_propertyType = AzToolsFramework::AudioPropertyType::Trigger;
  58. m_defaultStopTrigger.m_propertyType = AzToolsFramework::AudioPropertyType::Trigger;
  59. }
  60. //=========================================================================
  61. void EditorAudioTriggerComponent::BuildGameEntity(AZ::Entity* gameEntity)
  62. {
  63. gameEntity->CreateComponent<AudioTriggerComponent>(m_defaultPlayTrigger.m_controlName, m_defaultStopTrigger.m_controlName, m_obstructionType, m_playsImmediately);
  64. }
  65. } // namespace LmbrCentral