So, I simply want to create a registration menu and I've already done that. What I need help with is this:
1)If a player enters for the first time in the application, it means that it has no DeviceID and thus it needs to be created and only for this time, the player will have to insert the Username, Email and Password and after clicking the Submit button the app should continue.
2)If the player enters the app from the same device, it will automatically Log In without asking for any details since the Device ID exists in the database.
Thanks.
Answer by Sarah Zhang · May 03, 2021 at 09:54 AM
To implement your requirements, you need to keep the field “CreateAccount” of login API such as LoginWithAndroidDeviceID as “true” and do the API call in the Unity Start() function. Besides, you should add the judgment for the response of login API, if the value of “NewlyCreated” is true, it means it’s the first time for the player to enter the game, the player needs to provide the username, email, and password, and you should call the API AddUsernamePassword to submit the information. If the value of “NewlyCreated” false, it means it’s not the player’s first login, the player can enter the game directly. You can refer to the document -- Login basics and best Practices - PlayFab | Microsoft Docs for more information about best practice of integrating anonymous login and recoverable login.
The possible code sample could be something like this.
using PlayFab; using PlayFab.ClientModels; using System; using UnityEngine; using UnityEngine.UI; public class LoginSample : MonoBehaviour { public InputField UsernameInputField; public InputField EmailInputField; public InputField PasswordInputField; void Start() { var request = new LoginWithAndroidDeviceIDRequest { AndroidDeviceId = "GettingStartedGuide", CreateAccount = true }; PlayFabClientAPI.LoginWithAndroidDeviceID(request, OnLoginSuccess, OnFailure); } private void OnLoginSuccess(LoginResult result) { if (result.NewlyCreated) { //Display InputField UI var addUsernamePasswordRequest = new AddUsernamePasswordRequest { Username = UsernameInputField.text, Email = EmailInputField.text, Password = PasswordInputField.text }; PlayFabClientAPI.AddUsernamePassword(addUsernamePasswordRequest, OnAddSuccess, OnFailure); } else { //Enter the game logic } } private void OnAddSuccess(AddUsernamePasswordResult result) { //Enter the game logic } private void OnFailure(PlayFabError error) { Debug.LogError(error.GenerateErrorReport()); } }
,How to post user points to a certain leaderboard and get the leaderboard back in Unity? 1 Answer
Upload a file to player account From UNITY 3 Answers
Saving a custom character as a JSON 1 Answer
Stay logged in when the scene changes 1 Answer
How can I Store a list of strings or integers in Playfab 1 Answer