40 - Network Role
This commit is contained in:
parent
712fdb652e
commit
86ff124ae4
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -4,6 +4,7 @@
|
||||||
#include "BlasterCharacter.h"
|
#include "BlasterCharacter.h"
|
||||||
|
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
|
#include "Components/WidgetComponent.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "GameFramework/SpringArmComponent.h"
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
|
|
||||||
|
@ -23,6 +24,9 @@ ABlasterCharacter::ABlasterCharacter()
|
||||||
|
|
||||||
bUseControllerRotationYaw = false;
|
bUseControllerRotationYaw = false;
|
||||||
GetCharacterMovement()->bOrientRotationToMovement = true;
|
GetCharacterMovement()->bOrientRotationToMovement = true;
|
||||||
|
|
||||||
|
OverheadWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("OverheadWidget"));
|
||||||
|
OverheadWidget->SetupAttachment(RootComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::BeginPlay()
|
void ABlasterCharacter::BeginPlay()
|
||||||
|
|
|
@ -30,6 +30,9 @@ private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, Category="Camera")
|
UPROPERTY(VisibleAnywhere, Category="Camera")
|
||||||
class UCameraComponent* FollowCamera;
|
class UCameraComponent* FollowCamera;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
|
||||||
|
class UWidgetComponent* OverheadWidget;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "OverheadWidget.h"
|
||||||
|
|
||||||
|
#include "Components/TextBlock.h"
|
||||||
|
|
||||||
|
void UOverheadWidget::SetDisplayText(FString TextToDisplay)
|
||||||
|
{
|
||||||
|
if (DisplayText)
|
||||||
|
{
|
||||||
|
DisplayText->SetText(FText::FromString(TextToDisplay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOverheadWidget::ShowPlayerNetRole(APawn* InPawn)
|
||||||
|
{
|
||||||
|
ENetRole RemoveRole = InPawn->GetRemoteRole();
|
||||||
|
FString Role;
|
||||||
|
switch (RemoveRole)
|
||||||
|
{
|
||||||
|
case ENetRole::ROLE_Authority:
|
||||||
|
Role = FString("Authority");
|
||||||
|
break;
|
||||||
|
case ENetRole::ROLE_AutonomousProxy:
|
||||||
|
Role = FString("AutonomousProxy");
|
||||||
|
break;
|
||||||
|
case ENetRole::ROLE_SimulatedProxy:
|
||||||
|
Role = FString("SimulatedProxy");
|
||||||
|
break;
|
||||||
|
case ENetRole::ROLE_None:
|
||||||
|
Role = FString("None");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FString RemoteRoleString = FString::Printf(TEXT("Remote role: %s"), *Role);
|
||||||
|
SetDisplayText(RemoteRoleString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOverheadWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)
|
||||||
|
{
|
||||||
|
RemoveFromParent();
|
||||||
|
Super::OnLevelRemovedFromWorld(InLevel, InWorld);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "OverheadWidget.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class BLASTER_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;
|
||||||
|
};
|
Loading…
Reference in New Issue