49 lines
1.4 KiB
C#
Raw Permalink Normal View History

2025-09-19 14:56:58 +05:00
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Threading.Tasks;
namespace BulletHellTemplate
{
/// <summary>
/// This script handles logging out from Firebase, clearing PlayerPrefs, and returning to the login scene.
/// </summary>
public class LogOut : MonoBehaviour
{
[Header("Scene to load after logout")]
2025-09-19 19:43:49 +05:00
public string loginScene;
2025-09-19 14:56:58 +05:00
/// <summary>
/// Logs out the player from Firebase, clears PlayerPrefs, and loads the login scene.
/// </summary>
public async void PerformLogOut()
{
await LogOutFromFirebase();
// Clear PlayerPrefs data
PlayerPrefs.DeleteAll();
PlayerPrefs.Save();
Debug.Log("PlayerPrefs cleared. Logging out...");
// Load the login scene
if (loginScene != null)
{
SceneManager.LoadScene(loginScene);
}
else
{
Debug.LogError("Login scene reference is not set.");
}
}
/// <summary>
2025-09-19 19:43:49 +05:00
/// Logs out the current user from backend asynchronously.
2025-09-19 14:56:58 +05:00
/// </summary>
private async Task LogOutFromFirebase()
{
2025-09-19 19:43:49 +05:00
await BackendManager.Service.Logout();
await Task.Delay(100);
LoadingManager.Singleton.LoadSceneWithLoadingScreen(loginScene);
2025-09-19 14:56:58 +05:00
}
}
}