LEAP Documentation 40220
Documentation for the LEAP project
SpatialSoundComponent.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "SpatialSoundComponent.generated.h"
8
9UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
10class PROJECTX_API USpatialSoundComponent : public UActorComponent
11{
12 GENERATED_BODY()
13
14public:
15 /* Looping sound to play near and inside the volume */
16 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
17 class USoundBase* Sound;
18 /* Attenuation settings */
19 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
20 class USoundAttenuation* AttenuationSettings;
21 /* How often does the volume check for player proximity (per second) before activating itself? */
22 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
23 float InactiveTickInterval = 1.0f;
24 /* How often does the volume update the sound position (per second) when the player is near? */
25 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
26 float ActiveTickInterval = 0.1f;
27 /* How fast (in seconds) does the sound fade in as the player draws within attenuation range? */
28 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
29 float ActivationFadeInTime = 0.5f;
30 /* Play the spatial sound anywhere except inside the box */
31 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
32 bool bInvert = false;
33 /* Does the box position or size ever change? If so, check this box */
34 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
35 bool bIsDynamic = false;
36 /* Visualize the position of the spatial sound volume and the moving sound within it */
37 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Sound)
38 bool bShowDebug = false;
39
40 USpatialSoundComponent();
41
42 void Cleanup();
43 void RecalculateBox(const bool bForce = false);
44
45 virtual void BeginPlay() override;
46 virtual void OnWorldOriginChanged(UWorld* World, FIntVector SizeX, FIntVector SizeY);
47 virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
48
49private:
50 UPROPERTY()
51 class UAudioComponent* AudioComponent;
52 UPROPERTY()
53 class UBoxComponent* BoxComponent;
54
55 float FalloffSqured = 0.0f;
56
57 FBox SoundAreaInfo;
58
59 FVector GetSoundLocation(const AActor* const Listener) const;
60 FVector GetNearestPointInPerimeter(const FVector& Point) const;
61
62 void Optimize(const FVector& AudioComponentLocation, const AActor* const Listener);
63};