AkComponentVisualizer.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. /*=============================================================================
  16. AkComponentVisualizer.cpp:
  17. =============================================================================*/
  18. #include "AkComponentVisualizer.h"
  19. #include "AkAudioDevice.h"
  20. #include "AkComponent.h"
  21. #include "AkAudioEvent.h"
  22. #include "SceneView.h"
  23. #include "SceneManagement.h"
  24. #include "AkWaapiClient.h"
  25. #include "AkWaapiUtils.h"
  26. namespace FAkComponentVisualizer_Helper
  27. {
  28. float GetRadius(const UAkComponent* AkComponent)
  29. {
  30. if (auto waapiClient = FAkWaapiClient::Get())
  31. {
  32. FString AkAudioEventName = {};
  33. if(AkComponent->AkAudioEvent)
  34. {
  35. AkAudioEventName = AkComponent->AkAudioEvent->GetName();
  36. }
  37. if (!AkAudioEventName.IsEmpty())
  38. {
  39. TSharedRef<FJsonObject> args = MakeShared<FJsonObject>();
  40. {
  41. TSharedPtr<FJsonObject> from = MakeShared<FJsonObject>();
  42. from->SetArrayField(WwiseWaapiHelper::NAME, TArray<TSharedPtr<FJsonValue>>
  43. {
  44. MakeShared<FJsonValueString>(FString::Printf(TEXT("Event:%s"), *AkAudioEventName))
  45. });
  46. args->SetObjectField(WwiseWaapiHelper::FROM, from);
  47. }
  48. TSharedRef<FJsonObject> options = MakeShared<FJsonObject>();
  49. options->SetArrayField(WwiseWaapiHelper::RETURN, TArray<TSharedPtr<FJsonValue>>
  50. {
  51. MakeShared<FJsonValueString>(WwiseWaapiHelper::MAX_RADIUS_ATTENUATION)
  52. });
  53. #if AK_SUPPORT_WAAPI
  54. TSharedPtr<FJsonObject> result;
  55. if (waapiClient->Call(ak::wwise::core::object::get, args, options, result, 500, true))
  56. {
  57. TArray<TSharedPtr<FJsonValue>> ReturnArray = result->GetArrayField(WwiseWaapiHelper::RETURN);
  58. if (ReturnArray.Num() > 0)
  59. {
  60. const TSharedPtr<FJsonObject>* AttenuationObjectPtr = nullptr;
  61. if (ReturnArray[0]->AsObject()->TryGetObjectField(WwiseWaapiHelper::MAX_RADIUS_ATTENUATION, AttenuationObjectPtr))
  62. {
  63. return (*AttenuationObjectPtr)->GetNumberField(WwiseWaapiHelper::RADIUS);
  64. }
  65. }
  66. }
  67. #endif
  68. }
  69. }
  70. return AkComponent->GetAttenuationRadius();
  71. }
  72. }
  73. void FAkComponentVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI)
  74. {
  75. const UAkComponent* AkComponent = Cast<const UAkComponent>(Component);
  76. if (!AkComponent)
  77. return;
  78. if (AkComponent->outerRadius != 0.f)
  79. {
  80. FColor RadialEmitterColor(255, 255, 0);
  81. DrawWireSphereAutoSides(PDI, AkComponent->GetComponentLocation(), RadialEmitterColor, AkComponent->outerRadius, SDPG_World);
  82. }
  83. if (AkComponent->innerRadius != 0.f)
  84. {
  85. FColor RadialEmitterColor(204, 204, 0);
  86. DrawWireSphereAutoSides(PDI, AkComponent->GetComponentLocation(), RadialEmitterColor, AkComponent->innerRadius, SDPG_World);
  87. }
  88. if (!View->Family->EngineShowFlags.AudioRadius)
  89. return;
  90. auto radius = FAkComponentVisualizer_Helper::GetRadius(AkComponent);
  91. if (radius <= 0.0f)
  92. return;
  93. FColor AudioOuterRadiusColor(255, 153, 0);
  94. DrawWireSphereAutoSides(PDI, AkComponent->GetComponentLocation(), AudioOuterRadiusColor, radius, SDPG_World);
  95. }