5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "AmbianceComponent.generated.h"
12UCLASS(ClassGroup = (
Custom), meta = (BlueprintSpawnableComponent))
13class PROJECTX_API UAmbianceComponent :
public UActorComponent
19 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sounds")
20 FVector2D RandomSoundPlayDistance = FVector2D(1000.0f, 10000.0f);
22 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sounds")
23 FVector2D RandomSoundPlayDelay = FVector2D(1.0f, 3.0f);
25 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sounds")
26 USoundBase* AmbianceLooping;
28 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sounds")
29 TArray<USoundBase*> AmbianceOneShots;
31 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sounds", meta = (EditCondition="!bOverrideDefaultAmbiance"))
32 bool bIgnoreIfSameLoopingSound = false;
35 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sounds", meta = (EditCondition = "!bIgnoreIfSameLoopingSound"))
36 bool bOverrideDefaultAmbiance = false;
39 class UAudioComponent* AmbianceLoopingComponent;
45 virtual
void BeginPlay() override;
46 virtual
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
48 UAmbianceComponent* GetDefaultAmbiance(const APawn* Pawn);
49 bool StopAllOtherAmbiance();
50 bool StopAmbiance(UAmbianceComponent* Ambiance =
nullptr);
51 void PlayAmbiance(APawn* Listener,
bool bStopOtherAmbiance = false);
52 void PlayRandomSound(USoundBase* SoundToPlay);
53 void OverrideDefaultAmbiance(APawn* Pawn);
56 void OnAmbianceRegionEnter(AActor* OverlappedActor, AActor* OtherActor);
58 void OnAmbianceRegionExit(AActor* OverlappedActor, AActor* OtherActor);
60 FVector GetRandomSoundLocation() const;
61 FORCEINLINE
float GetRandomSoundDelay()
const {
return FMath::FRandRange(RandomSoundPlayDelay.X, RandomSoundPlayDelay.Y); }
64 static uint8 VolumeSemaphore;
65 static TWeakObjectPtr<UAmbianceComponent> DefaultAmbiance;
68 APawn* AmbianceCenter;