场景更改时保持登录状态(PlayFab、Unity)

问题描述 投票:0回答:0

我使用 Playfab 创建了一个登录系统。但问题是当我改变我的场景时它会自动注销。有什么方法可以保持登录状态吗?

public Text messageText;
  public Text messageReg;
  public Text messagelog;
  private string userEmail;
  private string userPassword;
  private string username;
  public GameObject loginPanel;
  public InputField emailInput;
 
  public static PlayfabManager PFM;
 
 
     public void OnEnable()
     {
         if (PlayfabManager.PFM == null)
         {
             PlayfabManager.PFM = this;
         }
         else
         {
             if (PlayfabManager.PFM != this)
             {
                 Destroy(this.gameObject);
             }
         }
         DontDestroyOnLoad(this.gameObject);
     }
 
     
 
 
 
     void Start()
     {
        
         if (string.IsNullOrEmpty(PlayFabSettings.TitleId))
         {
             PlayFabSettings.TitleId = " CFB1C";
         }
         //PlayerPrefs.DeleteAll();
 
         if (PlayerPrefs.HasKey("EMAIL"))
         {
             userEmail = PlayerPrefs.GetString("EMAIL");
             userPassword = PlayerPrefs.GetString("PASSWORD");
             var request = new LoginWithEmailAddressRequest
             {
                 Email = userEmail,
                 Password = userPassword
             };
             PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
         }
         
 
     }
 
     #region Login
     private void OnLoginSuccess(LoginResult result)
     {
         Debug.Log("Logged In!");
         PlayerPrefs.SetString("EMAIL", userEmail);
         PlayerPrefs.SetString("PASSWORD", userPassword);        
         messagelog.text = "Logged In!";
     }
    
     private void OnRegisterSuccess(RegisterPlayFabUserResult result)
     {
         Debug.Log("Register and logged In!");
         PlayerPrefs.SetString("EMAIL", userEmail);
         PlayerPrefs.SetString("PASSWORD", userPassword);
         messageReg.text = "Register and logged In!";
     }
 
     private void OnLoginFailure(PlayFabError error)
     {
         var registerRequest = new RegisterPlayFabUserRequest
         {
             Email = userEmail,
             Password = userPassword,
             Username = username,
         };
         PlayFabClientAPI.RegisterPlayFabUser(registerRequest, OnRegisterSuccess, OnRegisterFailure);
     }
 
     private void OnRegisterFailure(PlayFabError error)
     {
         Debug.LogError(error.GenerateErrorReport());
     }
 
     public void GetUserEmail(string emailIn)
     {
         userEmail = emailIn;
     }
 
     public void GetUserPassword(string passwordIn)
     {
         userPassword = passwordIn;
     }
 
     public void GetUsername(string usernameIn)
     {
         username = usernameIn;
     }
 
     public void OnClickLogin()
     {
          var request = new LoginWithEmailAddressRequest
          {
              Email = userEmail,
              Password = userPassword           
     };
     PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
     }
 
 

现在,有什么解决办法吗?我的意思是我可以在每个场景中保持登录状态吗?我是游戏开发领域的新手,目前正在从事我的第一个项目。

c# authentication unityscript multiplayer playfab
© www.soinside.com 2019 - 2024. All rights reserved.