c9.Spectating System|观战系统
小于 1 分钟
Spectating System
观战系统直观的分为两类,一类是主动观战系统比如比赛、观战模式。一类则是被动的,比如死亡观战。
1.观战类|SpectatorPawn
UMySpectatorPawnr : public APawn
2.观战类接口
MySpectatorPawn.h
virtual void SetupPlayerInputComponent(UInputComponent* InInputComponent) override;
/** Move camera to next player */
void ViewNextPlayer();
/** Move camera to previous player */
void ViewPrevPlayer();
MySpectatorPawn.cpp
void AMySpectatorPawn::SetupPlayerInputComponent(UInputComponent* InInputComponent)
{
Super::SetupPlayerInputComponent(InInputComponent);
InInputComponent->BindAction("ViewNext", IE_Pressed, this, &ThisClass::ViewNextPlayer);
InInputComponent->BindAction("ViewPrev", IE_Pressed, this, &ThisClass::ViewPrevPlayer);
}
void AMySpectatorPawn::ViewNextPlayer()
{
if (APlayerController* PC = GetController<APlayerController>())
{
PC->ServerViewNextPlayer();
}
}
void AMySpectatorPawn::ViewPrevPlayer()
{
if (APlayerController* PC = GetController<APlayerController>())
{
PC->ServerViewPrevPlayer();
}
}