Source\Unicorn\UnicornPlayerController.cpp
#include "UnicornPlayerController.h"
#include "PragmaPlayer.h"
#include "PragmaLocalPlayerSubsystem.h"
void AUnicornPlayerController::BeginPlay()
{
Super::BeginPlay();
const auto* Pragma = GetLocalPlayer()->GetSubsystem<UPragmaLocalPlayerSubsystem>();
Player = Pragma->Player();
// Log in using a built-in test account.
// Accounts test01 - test20 are available by default.
LogIn("test01");
}
void AUnicornPlayerController::LogIn(const FString& Username)
{
Player->LogIn(
EPragma_Account_IdProvider::UNSAFE,
Username,
Pragma::FPlayer::FLoggedInDelegate::CreateWeakLambda(
this, [this, Username = Username](const TPragmaResult<>& Result)
{
if (Result.IsSuccessful())
{
UE_LOG(LogTemp, Display, TEXT("Pragma -- Logged in as user %s."),
*Username);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Pragma -- Login failed: %s"),
*Result.GetErrorAsString());
}
}));
}
void AUnicornPlayerController::LogOut()
{
Player->LogOut(
Pragma::FPlayer::FLoggedOutDelegate::CreateWeakLambda(
this, []
{
UE_LOG(LogTemp, Display, TEXT("Pragma -- Logged out."));
}));
}