Files
Emberwild/Assets/Plugins/Easy Save 3/Scripts/ES3GlobalManager.cs
T
2026-06-22 16:18:34 +02:00

51 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scripting;
[assembly: AlwaysLinkAssembly]
public class ES3GlobalManager : MonoBehaviour
{
private static readonly WaitForEndOfFrame waitForEndOfFrame = new WaitForEndOfFrame();
// Indicates whether an event has indicated that the cache should be stored to file at the end of this frame.
bool storeCache = false;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Run()
{
var gameObject = new GameObject("Easy Save 3 Global Manager");
gameObject.AddComponent<ES3GlobalManager>();
DontDestroyOnLoad(gameObject);
if(ES3Settings.defaultSettings.autoCacheDefaultFile)
ES3.CacheFile();
}
public IEnumerator Start()
{
while (true)
{
yield return waitForEndOfFrame;
if((ES3Settings.defaultSettings.location == ES3.Location.Cache && ES3Settings.defaultSettings.storeCacheAtEndOfEveryFrame) || storeCache)
{
ES3File.StoreAll();
storeCache = false;
}
}
}
private void OnApplicationQuit()
{
if (ES3Settings.defaultSettings.storeCacheOnApplicationQuit)
storeCache = true;
}
private void OnApplicationPause(bool paused)
{
if ((ES3Settings.defaultSettings.storeCacheOnApplicationPause || (Application.isMobilePlatform && ES3Settings.defaultSettings.storeCacheOnApplicationQuit)) && paused)
storeCache = true;
}
}