using UnityEngine;
namespace Unity.VisualScripting
{
///
/// Listens to the OnApplicationQuit on OnApplicationPause
/// hooks to trigger the serialization of saved variables into PlayerPrefs.
///
[Singleton(Name = "VisualScripting SavedVariablesSerializer", Automatic = true, Persistent = true)]
[AddComponentMenu("")]
[DisableAnnotation]
[IncludeInSettings(false)]
public class VariablesSaver : MonoBehaviour, ISingleton
{
private void Awake()
{
Singleton.Awake(this);
}
private void OnDestroy()
{
Singleton.OnDestroy(this);
}
private void OnApplicationQuit()
{
SavedVariables.OnExitPlayMode();
ApplicationVariables.OnExitPlayMode();
}
private void OnApplicationPause(bool isPaused)
{
if (!isPaused)
{
return;
}
SavedVariables.OnExitPlayMode();
ApplicationVariables.OnExitPlayMode();
}
public static VariablesSaver instance => Singleton.instance;
public static void Instantiate() => Singleton.Instantiate();
}
}