すべてを統合する - デバイス ID でログインする - (Unity モジュール)
Connect the UI to let player log in with device ID
In this tutorial, you will learn how to connect the login menu user interface (UI) with the login methods you implemented previously. You are going to get the AuthEssentialsWrapper_Starter
class reference, set up the callback function OnLoginCompleted
in LoginHandler_Starter
, and start the login process from the existing LoginHandler.Login()
method you created.
Open Byte Wars in Unity. From Project window, open
/Assets/Resources/Modules/AuthEssentials/Scripts/UI/LoginHandler_Starter.cs
.Create a new callback function for
OnLoginCompleted
in theLoginHandler_Starter
file. Based on the ResultCallback, set to change the screen to the MainMenuCanvas using the in-game utility MenuManager on login success and set to change the view toLoginFailed
on login failed.public void OnLoginCompleted(Result<TokenData, OAuthError> result)
{
if (!result.IsError)
{
onLoginCompleted.Invoke(result.Value);
MenuManager.Instance.ChangeToMenu(AssetEnum.MainMenuCanvas);
BytewarsLogger.Log($"[LoginHandler.OnLoginCompleted] success: {result.Value.ToJsonString()}");
}
else
{
failedMessageText.text = $"Login Failed: {result.Error.error}";
CurrentView = LoginView.LoginFailed;
StartCoroutine(SetSelectedGameObject(retryLoginButton.gameObject));
}
}To access the
AuthEssentialsWrapper_Starter
class, you can useTutorialModuleManager
to get the reference easily, then store it to a local variable in the script'sStart()
.private AuthEssentialsWrapper_Starter authWrapper;
private void Start()
{
authWrapper = TutorialModuleManager.Instance.GetModuleClass<AuthEssentialsWrapper_Starter>();
...
}To enable retrying logins with the same method, prepare a local variable to store the last login method.
private LoginType lastLoginMethod;
Update the
LoginHandler_Starter.Login()
function by adding theLoginType
as a parameter. Inside the function, store the login method and call theAuthEssentialsWrapper_Starter.LoginWithDeviceId()
right after changing the view toLoginLoading
you created previously.private void Login(LoginType loginMethod)
{
CurrentView = LoginView.LoginLoading;
lastLoginMethod = loginMethod;
OnRetryLoginClicked = OnRetryLoginButtonClicked;
authWrapper.LoginWithDeviceId(OnLoginCompleted);
}Since you updated the
Login()
function, you also need to update theLogin()
function calls insideOnLoginWithDeviceIdButtonClicked()
andOnRetryLoginButtonClicked()
that are listening to theonClick
event ofloginWithDeviceIdButton
andquitGameButton
, respectively, that you created earlier.private void OnLoginWithDeviceIdButtonClicked()
{
Login(LoginType.DeviceId);
}private void OnRetryLoginButtonClicked()
{
Login(lastLoginMethod);
}