すべてを統合する - Steam でログインする - (Unreal Engine モジュール)
Last updated on May 30, 2024
Hook up the UI
In this tutorial, you will learn how to connect the W_SinglePlatformAuthWidget_Starter
widget to perform logins with Steam using the AuthEssentialsSubsystem_Starter
subsystem.
Open the SinglePlatformAuthWidget_Starter
class CPP file and add the following code to the OnLoginWithSinglePlatformAuthButtonClicked()
function.
void USinglePlatformAuthWidget_Starter::OnLoginWithSinglePlatformAuthButtonClicked()
{
...
// Use Auth Essentials's starter files for login if starter mode is active.
else
{
// Grab the login widget reference to show login state UI.
ULoginWidget_Starter* LoginWidget_Starter = Cast<ULoginWidget_Starter>(ParentWidget);
ensure(LoginWidget_Starter);
LoginWidget_Starter->SetLoginState(ELoginState::LoggingIn);
LoginWidget_Starter->OnRetryLoginDelegate.AddUObject(this, &ThisClass::OnLoginWithSinglePlatformAuthButtonClicked);
UAuthEssentialsSubsystem_Starter* AuthSubsystem_Starter = GetGameInstance()->GetSubsystem<UAuthEssentialsSubsystem_Starter>();
ensure(AuthSubsystem_Starter);
// Login with single platform auth is considered as a login with default native platform.
// Thus, it doesn't need a username, token, nor the login method.
AuthSubsystem_Starter->SetAuthCredentials(EAccelByteLoginType::None, TEXT(""), TEXT(""));
AuthSubsystem_Starter->Login(GetOwningPlayer(), FAuthOnLoginCompleteDelegate_Starter::CreateUObject(LoginWidget_Starter, & ULoginWidget_Starter::OnLoginComplete));
}
}
Now, when you press the login with Steam button, it will perform a login with Steam via the UAuthEssentialsSubsystem_Starter
subsystem. The callback will be handled by its parent widget W_Login_Starter
to direct the player to the Main Menu if the login is successful, or showing an error message if it fails. You can check the source code from the Login with device ID module.
Resources
- The files used in this tutorial section are available in the Byte Wars Unreal GitHub repository.
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/SteamAuthentication/UI/SinglePlatformAuthWidget_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/SteamAuthentication/UI/SinglePlatformAuthWidget_Starter.cpp
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/AuthEssentials/AuthEssentialsSubsystem_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/AuthEssentials/AuthEssentialsSubsystem_Starter.cpp