Add MVP campfire audio hooks
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "AgrarianPersistentActorComponent.h"
|
||||
#include "AgrarianSurvivalComponent.h"
|
||||
#include "Particles/ParticleSystemComponent.h"
|
||||
#include "Components/AudioComponent.h"
|
||||
#include "Components/PointLightComponent.h"
|
||||
#include "Components/StaticMeshComponent.h"
|
||||
#include "Engine/StaticMesh.h"
|
||||
@@ -108,6 +109,16 @@ AAgrarianCampfire::AAgrarianCampfire()
|
||||
SmokeEffect->SetRelativeLocation(FVector(0.0f, 0.0f, 80.0f));
|
||||
SmokeEffect->SetVisibility(false);
|
||||
|
||||
FireLoopAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("FireLoopAudioComponent"));
|
||||
FireLoopAudioComponent->SetupAttachment(RootComponent);
|
||||
FireLoopAudioComponent->bAutoActivate = false;
|
||||
FireLoopAudioComponent->bAllowSpatialization = true;
|
||||
|
||||
FireEventAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("FireEventAudioComponent"));
|
||||
FireEventAudioComponent->SetupAttachment(RootComponent);
|
||||
FireEventAudioComponent->bAutoActivate = false;
|
||||
FireEventAudioComponent->bAllowSpatialization = true;
|
||||
|
||||
PersistentActorComponent = CreateDefaultSubobject<UAgrarianPersistentActorComponent>(TEXT("PersistentActorComponent"));
|
||||
PersistentActorComponent->ActorTypeId = TEXT("campfire");
|
||||
}
|
||||
@@ -281,6 +292,23 @@ void AAgrarianCampfire::OnRep_FireState()
|
||||
UpdateVisualState();
|
||||
}
|
||||
|
||||
void AAgrarianCampfire::MulticastPlayFireEventSound_Implementation(bool bIgnited)
|
||||
{
|
||||
if (GetNetMode() == NM_DedicatedServer || !FireEventAudioComponent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
USoundBase* EventSound = bIgnited ? IgniteSound : ExtinguishSound;
|
||||
if (!EventSound)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FireEventAudioComponent->SetSound(EventSound);
|
||||
FireEventAudioComponent->Play();
|
||||
}
|
||||
|
||||
EAgrarianWeatherType AAgrarianCampfire::GetCurrentWeather() const
|
||||
{
|
||||
if (const UWorld* World = GetWorld())
|
||||
@@ -296,11 +324,17 @@ EAgrarianWeatherType AAgrarianCampfire::GetCurrentWeather() const
|
||||
|
||||
void AAgrarianCampfire::SetLit(bool bNewLit)
|
||||
{
|
||||
const bool bChanged = bLit != bNewLit;
|
||||
if (bLit != bNewLit)
|
||||
{
|
||||
bLit = bNewLit;
|
||||
}
|
||||
|
||||
if (HasAuthority() && bChanged)
|
||||
{
|
||||
MulticastPlayFireEventSound(bLit);
|
||||
}
|
||||
|
||||
UpdateVisualState();
|
||||
}
|
||||
|
||||
@@ -323,6 +357,25 @@ void AAgrarianCampfire::UpdateVisualState()
|
||||
SmokeEffect->DeactivateSystem();
|
||||
}
|
||||
}
|
||||
|
||||
if (FireLoopAudioComponent)
|
||||
{
|
||||
if (bLit && FireLoopSound)
|
||||
{
|
||||
if (FireLoopAudioComponent->Sound != FireLoopSound)
|
||||
{
|
||||
FireLoopAudioComponent->SetSound(FireLoopSound);
|
||||
}
|
||||
if (!FireLoopAudioComponent->IsPlaying())
|
||||
{
|
||||
FireLoopAudioComponent->Play();
|
||||
}
|
||||
}
|
||||
else if (FireLoopAudioComponent->IsPlaying())
|
||||
{
|
||||
FireLoopAudioComponent->Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianCampfire::WarmNearbyCharacters(float DeltaSeconds)
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
class UPointLightComponent;
|
||||
class UParticleSystemComponent;
|
||||
class UAgrarianPersistentActorComponent;
|
||||
class UAudioComponent;
|
||||
class USoundBase;
|
||||
class UStaticMeshComponent;
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
@@ -49,6 +51,12 @@ public:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Fire|Effects")
|
||||
TObjectPtr<UParticleSystemComponent> SmokeEffect;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Fire|Audio")
|
||||
TObjectPtr<UAudioComponent> FireLoopAudioComponent;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Fire|Audio")
|
||||
TObjectPtr<UAudioComponent> FireEventAudioComponent;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Fire|Persistence")
|
||||
TObjectPtr<UAgrarianPersistentActorComponent> PersistentActorComponent;
|
||||
|
||||
@@ -85,6 +93,15 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Weather")
|
||||
bool bWetWeatherCanExtinguish = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Audio")
|
||||
TObjectPtr<USoundBase> FireLoopSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Audio")
|
||||
TObjectPtr<USoundBase> IgniteSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Audio")
|
||||
TObjectPtr<USoundBase> ExtinguishSound;
|
||||
|
||||
virtual FText GetInteractionText_Implementation(const AAgrarianGameCharacter* Interactor) const override;
|
||||
virtual bool CanInteract_Implementation(const AAgrarianGameCharacter* Interactor) const override;
|
||||
virtual void Interact_Implementation(AAgrarianGameCharacter* Interactor) override;
|
||||
@@ -113,6 +130,9 @@ protected:
|
||||
UFUNCTION()
|
||||
void OnRep_FireState();
|
||||
|
||||
UFUNCTION(NetMulticast, Unreliable)
|
||||
void MulticastPlayFireEventSound(bool bIgnited);
|
||||
|
||||
EAgrarianWeatherType GetCurrentWeather() const;
|
||||
void SetLit(bool bNewLit);
|
||||
void UpdateVisualState();
|
||||
|
||||
Reference in New Issue
Block a user