setup npc visuals
This commit is contained in:
@@ -67,11 +67,13 @@ void UNPCDirectorSubsystem::PrewarmPool()
|
||||
|
||||
for (int32 i = 0; i < Config->MaxNPCs; ++i)
|
||||
{
|
||||
const TSubclassOf<ANPC> NPCClass = PickWeightedClass();
|
||||
if (!NPCClass)
|
||||
const ENPCType NPCType = PickWeightedClass();
|
||||
if (NPCType == ENPCType::None)
|
||||
continue;
|
||||
|
||||
ANPC* NPC = World->SpawnActor<ANPC>(NPCClass, FVector::ZeroVector, FRotator::ZeroRotator, Params);
|
||||
TSubclassOf<ANPC> SelectedNPCClass = GetRandomNPCClass(Config->NPCClasses);
|
||||
ANPC* NPC = World->SpawnActor<ANPC>(SelectedNPCClass, FVector::ZeroVector, FRotator::ZeroRotator, Params);
|
||||
NPC->Init(NPCType);
|
||||
if (!NPC)
|
||||
continue;
|
||||
|
||||
@@ -169,31 +171,31 @@ void UNPCDirectorSubsystem::ReturnToPool(ANPC* NPC)
|
||||
}
|
||||
}
|
||||
|
||||
TSubclassOf<ANPC> UNPCDirectorSubsystem::PickWeightedClass() const
|
||||
ENPCType UNPCDirectorSubsystem::PickWeightedClass() const
|
||||
{
|
||||
const UNPCDirectorConfig* Config = GetConfig();
|
||||
if (!Config)
|
||||
return nullptr;
|
||||
return ENPCType::None;
|
||||
|
||||
float TotalWeight = 0.0f;
|
||||
for (const FNPCSpawnEntry& Entry : Config->SpawnTable)
|
||||
{
|
||||
if (Entry.NPCClass && Entry.Weight > 0.0f)
|
||||
if (Entry.Type != ENPCType::None && Entry.Weight > 0.0f)
|
||||
TotalWeight += Entry.Weight;
|
||||
}
|
||||
if (TotalWeight <= 0.0f)
|
||||
return nullptr;
|
||||
return ENPCType::None;
|
||||
|
||||
float Roll = FMath::FRandRange(0.0f, TotalWeight);
|
||||
for (const FNPCSpawnEntry& Entry : Config->SpawnTable)
|
||||
{
|
||||
if (!Entry.NPCClass || Entry.Weight <= 0.0f)
|
||||
if (Entry.Type == ENPCType::None || Entry.Weight <= 0.0f)
|
||||
continue;
|
||||
Roll -= Entry.Weight;
|
||||
if (Roll <= 0.0f)
|
||||
return Entry.NPCClass;
|
||||
return Entry.Type;
|
||||
}
|
||||
return nullptr;
|
||||
return ENPCType::None;
|
||||
}
|
||||
|
||||
bool UNPCDirectorSubsystem::FindSpawnPoint(const FVector& Around, FVector& OutLocation) const
|
||||
@@ -219,6 +221,12 @@ bool UNPCDirectorSubsystem::FindSpawnPoint(const FVector& Around, FVector& OutLo
|
||||
return false;
|
||||
}
|
||||
|
||||
TSubclassOf<ANPC> UNPCDirectorSubsystem::GetRandomNPCClass(TArray<TSubclassOf<ANPC>> InNPCClasses)
|
||||
{
|
||||
const int32 RandomIndex = FMath::RandRange(0, InNPCClasses.Num() - 1);
|
||||
return InNPCClasses[RandomIndex];
|
||||
}
|
||||
|
||||
APawn* UNPCDirectorSubsystem::GetPlayerPawn() const
|
||||
{
|
||||
return UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
|
||||
|
||||
Reference in New Issue
Block a user