60 lines
1.2 KiB
C#
60 lines
1.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Studio
|
|
{
|
|
|
|
public class QuitManager : MonoBehaviour
|
|
{
|
|
private bool quitConfirmed;
|
|
private bool popupOpened;
|
|
|
|
public Action onOpen;
|
|
|
|
private void OnEnable()
|
|
{
|
|
Application.wantsToQuit += HandleForcedExitRequest;
|
|
}
|
|
protected override void OnDestroy()
|
|
{
|
|
Application.wantsToQuit -= HandleForcedExitRequest;
|
|
}
|
|
|
|
public bool HandleForcedExitRequest()
|
|
{
|
|
if (quitConfirmed)
|
|
return true;
|
|
|
|
if (!popupOpened)
|
|
{
|
|
popupOpened = true;
|
|
onOpen?.Invoke();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
public void HandleManualExitRequest()
|
|
{
|
|
if (!popupOpened)
|
|
{
|
|
popupOpened = true;
|
|
onOpen?.Invoke();
|
|
}
|
|
}
|
|
|
|
public void OnConfirmQuit()
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#endif
|
|
quitConfirmed = true;
|
|
Application.Quit();
|
|
}
|
|
|
|
public void OnCancelQuit()
|
|
{
|
|
popupOpened = false;
|
|
}
|
|
}
|
|
}
|