70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
using Firebase.Auth;
|
||
|
using System.Threading.Tasks;
|
||
|
using UnityEditor;
|
||
|
|
||
|
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")]
|
||
|
public string loginScene; // SceneAsset reference to the login scene
|
||
|
|
||
|
private FirebaseAuth auth;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
// Initialize Firebase Auth
|
||
|
auth = FirebaseAuth.DefaultInstance;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Logs out the player from Firebase, clears PlayerPrefs, and loads the login scene.
|
||
|
/// </summary>
|
||
|
public async void PerformLogOut()
|
||
|
{
|
||
|
// Perform Firebase logout
|
||
|
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>
|
||
|
/// Logs out the current user from Firebase asynchronously.
|
||
|
/// </summary>
|
||
|
private async Task LogOutFromFirebase()
|
||
|
{
|
||
|
if (auth.CurrentUser != null)
|
||
|
{
|
||
|
// Sign out from Firebase
|
||
|
auth.SignOut();
|
||
|
Debug.Log("User signed out from Firebase.");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.LogWarning("No user is logged in to Firebase.");
|
||
|
}
|
||
|
|
||
|
// Simulating waiting for any asynchronous operations, if needed
|
||
|
await Task.Delay(100); // Just a small delay to ensure smooth logout process
|
||
|
}
|
||
|
}
|
||
|
}
|