Implemented Voice Randomizer for Walking NPCs
This commit is contained in:
parent
0a74af3f44
commit
bbdf749e11
BIN
EndlessVendetta/Content/Levels/OpenWorldRework.umap
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Levels/OpenWorldRework.umap
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/NPC/BP_NPC_Manager.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/NPC/BP_NPC_Manager.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Blueprints/Blueprint_CeilingLight.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Blueprints/Blueprint_CeilingLight.uasset
(Stored with Git LFS)
Binary file not shown.
@ -43,6 +43,9 @@ void ANPC_Manager::SpawnNPC_Walkers()
|
|||||||
FRotator Rot = WalkersSpawnTransform.GetRotation().Rotator();
|
FRotator Rot = WalkersSpawnTransform.GetRotation().Rotator();
|
||||||
ANPC_WalkerClass* SpawnedWalker = GetWorld()->SpawnActor<ANPC_WalkerClass>(NPC_Walker, Loc, Rot);
|
ANPC_WalkerClass* SpawnedWalker = GetWorld()->SpawnActor<ANPC_WalkerClass>(NPC_Walker, Loc, Rot);
|
||||||
NPC_Walkers.Add(SpawnedWalker);
|
NPC_Walkers.Add(SpawnedWalker);
|
||||||
|
if (VoiceLinesCollection.IsEmpty()) continue;
|
||||||
|
int i = FMath::RandRange(0, VoiceLinesCollection.Num() - 1);
|
||||||
|
SpawnedWalker->SetVoiceline(VoiceLinesCollection[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "GameFramework/Actor.h"
|
#include "GameFramework/Actor.h"
|
||||||
#include "NPC_Manager.generated.h"
|
#include "NPC_Manager.generated.h"
|
||||||
|
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class ENDLESSVENDETTA_API ANPC_Manager : public AActor
|
class ENDLESSVENDETTA_API ANPC_Manager : public AActor
|
||||||
{
|
{
|
||||||
@ -49,6 +50,10 @@ protected:
|
|||||||
UPROPERTY(EditAnywhere, Category = "NPC", meta = (MakeEditWidget = "true"))
|
UPROPERTY(EditAnywhere, Category = "NPC", meta = (MakeEditWidget = "true"))
|
||||||
TArray<FVector> StationPoints;
|
TArray<FVector> StationPoints;
|
||||||
|
|
||||||
|
// VoiceLines used for randomly distributing amongst walking NPCs
|
||||||
|
UPROPERTY(EditDefaultsOnly, Category = "NPC")
|
||||||
|
TArray<FVoiceLines> VoiceLinesCollection;
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "NPC_WalkerClass.h"
|
#include "NPC_WalkerClass.h"
|
||||||
|
|
||||||
|
#include "Components/AudioComponent.h"
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
ANPC_WalkerClass::ANPC_WalkerClass()
|
ANPC_WalkerClass::ANPC_WalkerClass()
|
||||||
{
|
{
|
||||||
@ -33,5 +35,16 @@ void ANPC_WalkerClass::DisableNPC()
|
|||||||
bIsEnabled = false;
|
bIsEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ANPC_WalkerClass::Interact()
|
||||||
|
{
|
||||||
|
if (VoiceLines.IsEmpty()) return;
|
||||||
|
UAudioComponent* Audio = Cast<UAudioComponent>(GetComponentByClass(UAudioComponent::StaticClass()));;
|
||||||
|
if (!IsValid(Audio)) return;
|
||||||
|
int i = FMath::RandRange(0, VoiceLines.Num() - 1);
|
||||||
|
if (!IsValid(VoiceLines[i])) return;
|
||||||
|
Audio->Sound = VoiceLines[i];
|
||||||
|
Audio->Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,17 +3,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "VoicelinesStruct.h"
|
||||||
|
#include "EndlessVendetta/InteractionInterface.h"
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "NPC_WalkerClass.generated.h"
|
#include "NPC_WalkerClass.generated.h"
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class ENDLESSVENDETTA_API ANPC_WalkerClass : public ACharacter
|
class ENDLESSVENDETTA_API ANPC_WalkerClass : public ACharacter, public IInteractionInterface
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
int WalkingSpotIndex = 0;
|
int WalkingSpotIndex = 0;
|
||||||
int Polarity = 1;
|
int Polarity = 1;
|
||||||
bool bIsEnabled = true;
|
bool bIsEnabled = true;
|
||||||
|
TArray<USoundBase*> VoiceLines;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UPROPERTY(EditAnywhere, Category = "NPC", meta = (MakeEditWidget = "true"))
|
UPROPERTY(EditAnywhere, Category = "NPC", meta = (MakeEditWidget = "true"))
|
||||||
@ -33,4 +36,11 @@ public:
|
|||||||
|
|
||||||
void DisableNPC();
|
void DisableNPC();
|
||||||
|
|
||||||
|
void SetVoiceline(FVoiceLines VL)
|
||||||
|
{
|
||||||
|
VoiceLines = VL.Voices;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Interact() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
#include "VoicelinesStruct.h"
|
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "VoicelinesStruct.generated.h"
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FVoiceLines
|
||||||
|
{
|
||||||
|
GENERATED_BODY();
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "NPC")
|
||||||
|
TArray<USoundBase*> Voices;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user