60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using System;
|
|
|
|
public class ExitGame : MonoBehaviour
|
|
{
|
|
public GameObject exitPanel;
|
|
|
|
void Update()
|
|
{
|
|
// Jika tombol ESC ditekan, tampilkan panel
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
ToggleExitPanel();
|
|
}
|
|
}
|
|
|
|
public void ToggleExitPanel()
|
|
{
|
|
exitPanel.SetActive(!exitPanel.activeSelf);
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
Debug.Log("Keluar dari game...");
|
|
Application.Quit();
|
|
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#endif
|
|
}
|
|
|
|
public void CancelExit()
|
|
{
|
|
exitPanel.SetActive(false);
|
|
}
|
|
|
|
public void Logout()
|
|
{
|
|
string kodeLogin = PlayerPrefs.GetString("kodeLogin", "default");
|
|
|
|
// (Opsional) Simpan progres ke Firebase sebelum logout
|
|
foreach (var pair in LevelControl.Instance.materiLevelPairs)
|
|
{
|
|
string key = $"{kodeLogin}_{pair.materiName}_UnlockedLevel";
|
|
int unlocked = PlayerPrefs.GetInt(key, 1);
|
|
|
|
DBManager.SaveUnlockedLevel(kodeLogin, pair.materiName, unlocked); // simpan ke Firebase
|
|
}
|
|
|
|
PlayerPrefs.DeleteKey("kodeLogin");
|
|
PlayerPrefs.Save();
|
|
|
|
Debug.Log("User telah logout.");
|
|
SceneManager.LoadScene("InputUser");
|
|
}
|
|
}
|