AkRoomComponent.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #pragma once
  16. #include "AkReverbDescriptor.h"
  17. #include "GameFramework/Volume.h"
  18. #include "AkGameObject.h"
  19. #include "AkRoomComponent.generated.h"
  20. class UAkLateReverbComponent;
  21. UCLASS(ClassGroup = Audiokinetic, BlueprintType, hidecategories = (Transform, Rendering, Mobility, LOD, Component, Activation, Tags), meta = (BlueprintSpawnableComponent))
  22. class AKAUDIO_API UAkRoomComponent : public UAkGameObject
  23. {
  24. GENERATED_BODY()
  25. public:
  26. UAkRoomComponent(const class FObjectInitializer& ObjectInitializer);
  27. /**
  28. * Enable room transmission feature. Additional properties are available in the Room category.
  29. * If Enable Room begins as false, changing Enable Room during runtime will only have an effect
  30. * if Room Is Dynamic = true.
  31. */
  32. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Toggle, meta = (DisplayName = "Enable Room"))
  33. bool bEnable = false;
  34. /**
  35. * If true, the portal connections for this room can change during runtime when this room moves.
  36. * For worlds containing many portals, this can be expensive. Note that this room's portal connections
  37. * may still change, even when Room Is Dynamic = false, when dynamic portals are moved (i.e. when portals
  38. * move who have bDynamic = true).
  39. * When Room Is Dynamic = true, enabling and disabling rooms will have immediate effect, without needing
  40. * to update emitters and/or listeners directly. */
  41. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Toggle, meta = (DisplayName = "Room Is Dynamic"))
  42. bool bDynamic = false;
  43. /**
  44. * The precedence in which the Rooms will be applied. In the case of overlapping rooms, only the one
  45. * with the highest priority is chosen. If two or more overlapping rooms have the same
  46. * priority, the chosen room is unpredictable.
  47. */
  48. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Room")
  49. float Priority = .0f;
  50. /**
  51. * Used to set the transmission loss value in wwise, on emitters in the room, when no audio paths to the
  52. * listener are found via sound propagation in Wwise Spatial Audio. This value can be thought of as
  53. * 'thickness', as it relates to how much sound energy is transmitted through the wall. Valid range 0.0f-1.0f,
  54. * and is mapped to the occlusion curve as defined in the Wwise project.
  55. */
  56. UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName = "Transmission Loss", Category = "Room", meta = (ClampMin=0.0f, ClampMax=1.0f, UIMin=0.0f, UIMax=1.0f))
  57. float WallOcclusion = .0f;
  58. /**
  59. * Send level for sounds that are posted on the room. Valid range: (0.f-1.f). A value of 0 disables the aux send.
  60. */
  61. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AkEvent", meta = (ClampMin = "0.0", ClampMax = "1.0"))
  62. float AuxSendLevel = .0f;
  63. /** Automatically post the associated AkAudioEvent on BeginPlay */
  64. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AkEvent", SimpleDisplay)
  65. bool AutoPost = false;
  66. /** Posts this game object's AkAudioEvent to Wwise, using this as the game object source */
  67. virtual int32 PostAssociatedAkEvent(
  68. UPARAM(meta = (Bitmask, BitmaskEnum = "/Script/AkAudio.EAkCallbackType")) int32 CallbackMask,
  69. const FOnAkPostEventCallback& PostEventCallback
  70. );
  71. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|AkRoomComponent")
  72. UPrimitiveComponent* GetPrimitiveParent() const;
  73. /** Register a room in AK Spatial Audio. */
  74. void AddSpatialAudioRoom();
  75. /** Modify a room in AK Spatial Audio. */
  76. void UpdateSpatialAudioRoom();
  77. /** Remove a room from AK Spatial Audio */
  78. void RemoveSpatialAudioRoom();
  79. bool HasEffectOnLocation(const FVector& Location) const;
  80. bool RoomIsActive() const;
  81. AkRoomID GetRoomID() const { return AkRoomID(this); }
  82. virtual void OnRegister() override;
  83. virtual void OnUnregister() override;
  84. #if WITH_EDITOR
  85. virtual void BeginDestroy() override;
  86. virtual void OnComponentCreated() override;
  87. virtual void InitializeComponent() override;
  88. virtual void PostLoad() override;
  89. virtual void OnComponentDestroyed(bool bDestroyingHierarchy) override;
  90. #endif
  91. virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction) override;
  92. virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport) override;
  93. virtual bool MoveComponentImpl(
  94. const FVector & Delta,
  95. const FQuat & NewRotation,
  96. bool bSweep,
  97. FHitResult * Hit,
  98. EMoveComponentFlags MoveFlags,
  99. ETeleportType Teleport) override;
  100. FName GetName() const;
  101. virtual AkPlayingID PostAkEventByNameWithDelegate(
  102. UAkAudioEvent* AkEvent,
  103. const FString& in_EventName,
  104. int32 CallbackMask, const FOnAkPostEventCallback& PostEventCallback);
  105. // Begin USceneComponent Interface
  106. virtual void BeginPlay() override;
  107. virtual void EndPlay(EEndPlayReason::Type EndPlayReason) override;
  108. #if WITH_EDITOR
  109. virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
  110. #endif
  111. /** Set the geometry component that will be used to send the geometry of the room to Wwise. For example, in a Blueprint that has a static mesh component with an AkGeometry child component, this function can be called in BeginPlay to associate that AkGeometry component with this room component.
  112. * If this room component has a sibling geometry component (or surface reflector set component), they will be associated automatically and there is no need to call this function.
  113. */
  114. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|AkRoomComponent")
  115. void SetGeometryComponent(UAkAcousticTextureSetComponent* textureSetComponent);
  116. FString GetRoomName();
  117. UAkLateReverbComponent* GetReverbComponent();
  118. private:
  119. class UPrimitiveComponent* Parent;
  120. UPROPERTY(Transient)
  121. class UAkAcousticTextureSetComponent* GeometryComponent = nullptr;
  122. void InitializeParent();
  123. void GetRoomParams(AkRoomParams& outParams);
  124. bool EncompassesPoint(FVector Point, float SphereRadius = 0.f, float* OutDistanceToPoint = nullptr) const;
  125. void BeginPlayInternal();
  126. void SendGeometry();
  127. void RemoveGeometry();
  128. float SecondsSinceMovement = 0.0f;
  129. bool Moving = false;
  130. #if WITH_EDITOR
  131. void HandleObjectsReplaced(const TMap<UObject*, UObject*>& ReplacementMap);
  132. bool bRequiresDeferredBeginPlay = false;
  133. class UDrawRoomComponent* DrawRoomComponent = nullptr;
  134. void RegisterVisEnabledCallback();
  135. void InitializeDrawComponent();
  136. void DestroyDrawComponent();
  137. FDelegateHandle ShowRoomsChangedHandle;
  138. #endif
  139. };