플레이어 Role 머리 위에 띄우기

 


 

Travel in Multiplayer

 

게임에 입장한 플레이어가 Server쪽인지 Client쪽인지 구분해야 한다.

코드를 구현할 때 RPC를 고려하여야 한다.


 

OverheadWidget

 

OverheadWidget.h

더보기
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "OverheadWidget.generated.h"
UCLASS()
class MULTIPLAYER_API UOverheadWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(meta = (BindWidget))
class UTextBlock* DisplayText;
void SetDisplayText(FString TextToDisplay);
UFUNCTION(BlueprintCallable)
void ShowPlayerNetRole(APawn* InPawn);
protected:
virtual void OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld) override;
};

 

OverheadWidget.cpp

더보기
#include "OverheadWidget.h"
#include "Components/TextBlock.h"
void UOverheadWidget::SetDisplayText(FString TextToDisplay)
{
if (IsValid(DisplayText))
{
DisplayText->SetText(FText::FromString(TextToDisplay));//TextToDisplay 변수로 들어오는 text로 설정.
}
}
void UOverheadWidget::ShowPlayerNetRole(APawn* InPawn)
{
ENetRole RemoteRole = InPawn->GetRemoteRole();// Pawn의 Role이 뭔지 담는 변수
FString Role;
switch (RemoteRole)
{
case ENetRole::ROLE_Authority:
Role = FString("Authority");
break;
case ENetRole::ROLE_AutonomousProxy:
Role = FString("Autonomous Proxy");
break;
case ENetRole::ROLE_SimulatedProxy:
Role = FString("Simulated Proxy");
break;
case ENetRole::ROLE_None:
Role = FString("None");
break;
}
FString RemoteRoleString = FString::Printf(TEXT("Remote Role: %s"), *Role);
SetDisplayText(RemoteRoleString);// Pawn의 Role이 무엇인지 화면에 띄워준다.
}
void UOverheadWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)
{
RemoveFromParent();
Super::OnLevelRemovedFromWorld(InLevel, InWorld);
}

 

 

BP_BaseCharacter

 


 

실행화면