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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user