Add MVP wildlife audio hooks
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "AgrarianGameCharacter.h"
|
||||
#include "AgrarianInventoryComponent.h"
|
||||
#include "AIController.h"
|
||||
#include "Components/AudioComponent.h"
|
||||
#include "Components/StaticMeshComponent.h"
|
||||
#include "Engine/StaticMesh.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
@@ -86,6 +87,11 @@ AAgrarianWildlifeBase::AAgrarianWildlifeBase()
|
||||
WildlifeTailProxy->SetRelativeRotation(FRotator(0.0f, 90.0f, 90.0f));
|
||||
WildlifeTailProxy->SetRelativeScale3D(FVector(0.12f, 0.12f, 0.24f));
|
||||
|
||||
WildlifeAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("WildlifeAudioComponent"));
|
||||
WildlifeAudioComponent->SetupAttachment(RootComponent);
|
||||
WildlifeAudioComponent->bAutoActivate = false;
|
||||
WildlifeAudioComponent->bAllowSpatialization = true;
|
||||
|
||||
DisplayName = FText::FromString(TEXT("Wildlife"));
|
||||
}
|
||||
|
||||
@@ -168,6 +174,10 @@ void AAgrarianWildlifeBase::SetWildlifeState(EAgrarianWildlifeState NewState)
|
||||
}
|
||||
|
||||
WildlifeState = NewState;
|
||||
if (HasAuthority())
|
||||
{
|
||||
MulticastPlayWildlifeStateSound(WildlifeState);
|
||||
}
|
||||
BroadcastStateChanged();
|
||||
}
|
||||
|
||||
@@ -204,6 +214,34 @@ void AAgrarianWildlifeBase::OnRep_WildlifeState()
|
||||
BroadcastStateChanged();
|
||||
}
|
||||
|
||||
void AAgrarianWildlifeBase::MulticastPlayWildlifeStateSound_Implementation(EAgrarianWildlifeState NewState)
|
||||
{
|
||||
if (GetNetMode() == NM_DedicatedServer || !WildlifeAudioComponent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
USoundBase* StateSound = GetSoundForWildlifeState(NewState);
|
||||
if (!StateSound)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WildlifeAudioComponent->SetSound(StateSound);
|
||||
WildlifeAudioComponent->Play();
|
||||
}
|
||||
|
||||
void AAgrarianWildlifeBase::MulticastPlayWildlifeHarvestSound_Implementation()
|
||||
{
|
||||
if (GetNetMode() == NM_DedicatedServer || !WildlifeAudioComponent || !HarvestWildlifeSound)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WildlifeAudioComponent->SetSound(HarvestWildlifeSound);
|
||||
WildlifeAudioComponent->Play();
|
||||
}
|
||||
|
||||
bool AAgrarianWildlifeBase::ShouldRunServerThink(float DeltaSeconds)
|
||||
{
|
||||
if (!bEnablePerformanceLimits || WildlifeState == EAgrarianWildlifeState::Dead)
|
||||
@@ -524,6 +562,7 @@ bool AAgrarianWildlifeBase::Harvest(AAgrarianGameCharacter* Interactor)
|
||||
}
|
||||
|
||||
bHarvested = true;
|
||||
MulticastPlayWildlifeHarvestSound();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -536,3 +575,19 @@ void AAgrarianWildlifeBase::BroadcastStateChanged()
|
||||
{
|
||||
OnWildlifeStateChanged.Broadcast(WildlifeState);
|
||||
}
|
||||
|
||||
USoundBase* AAgrarianWildlifeBase::GetSoundForWildlifeState(EAgrarianWildlifeState State) const
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case EAgrarianWildlifeState::Fleeing:
|
||||
case EAgrarianWildlifeState::Chasing:
|
||||
return FleeWildlifeSound;
|
||||
case EAgrarianWildlifeState::Dead:
|
||||
return DeathWildlifeSound;
|
||||
case EAgrarianWildlifeState::Idle:
|
||||
case EAgrarianWildlifeState::Wandering:
|
||||
default:
|
||||
return IdleWildlifeSound;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "AgrarianWildlifeBase.generated.h"
|
||||
|
||||
class AAgrarianGameCharacter;
|
||||
class UAudioComponent;
|
||||
class USoundBase;
|
||||
class UStaticMeshComponent;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAgrarianWildlifeStateChangedSignature, EAgrarianWildlifeState, NewState);
|
||||
@@ -46,6 +48,9 @@ public:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Wildlife|Visuals")
|
||||
TObjectPtr<UStaticMeshComponent> WildlifeTailProxy;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Wildlife|Audio")
|
||||
TObjectPtr<UAudioComponent> WildlifeAudioComponent;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Wildlife")
|
||||
FName WildlifeId = TEXT("wildlife");
|
||||
|
||||
@@ -109,6 +114,18 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Agrarian|Wildlife|Harvest")
|
||||
bool bHarvested = false;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Wildlife|Audio")
|
||||
TObjectPtr<USoundBase> IdleWildlifeSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Wildlife|Audio")
|
||||
TObjectPtr<USoundBase> FleeWildlifeSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Wildlife|Audio")
|
||||
TObjectPtr<USoundBase> DeathWildlifeSound;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Wildlife|Audio")
|
||||
TObjectPtr<USoundBase> HarvestWildlifeSound;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Wildlife")
|
||||
bool IsAlive() const;
|
||||
|
||||
@@ -131,6 +148,12 @@ protected:
|
||||
UFUNCTION()
|
||||
void OnRep_WildlifeState();
|
||||
|
||||
UFUNCTION(NetMulticast, Unreliable)
|
||||
void MulticastPlayWildlifeStateSound(EAgrarianWildlifeState NewState);
|
||||
|
||||
UFUNCTION(NetMulticast, Unreliable)
|
||||
void MulticastPlayWildlifeHarvestSound();
|
||||
|
||||
bool ShouldRunServerThink(float DeltaSeconds);
|
||||
void ServerThink(float DeltaSeconds);
|
||||
void ChooseWanderTarget();
|
||||
@@ -146,6 +169,7 @@ protected:
|
||||
bool Harvest(AAgrarianGameCharacter* Interactor);
|
||||
void BroadcastHealthChanged();
|
||||
void BroadcastStateChanged();
|
||||
USoundBase* GetSoundForWildlifeState(EAgrarianWildlifeState State) const;
|
||||
|
||||
UPROPERTY()
|
||||
FVector SpawnLocation = FVector::ZeroVector;
|
||||
|
||||
Reference in New Issue
Block a user