2026-03-20 11:56:50 -04:00
using System.Collections.Generic ;
using ES3Internal ;
using UnityEngine ;
2025-10-03 00:02:43 -04:00
public class ES3AutoSave : MonoBehaviour , ISerializationCallbackReceiver
{
public bool saveLayer = true ;
public bool saveTag = true ;
public bool saveName = true ;
public bool saveHideFlags = true ;
public bool saveActive = true ;
2026-03-20 11:56:50 -04:00
public bool saveChildren ;
2025-10-03 00:02:43 -04:00
public bool saveDestroyed = true ;
//[HideInInspector]
2026-03-20 11:56:50 -04:00
public List < Component > componentsToSave = new ( ) ;
private bool isQuitting ;
public void Awake ( )
{
if ( ES3AutoSaveMgr . Current = = null )
ES3Debug . LogWarning (
"<b>No GameObjects in this scene will be autosaved</b> because there is no Easy Save 3 Manager. To add a manager to this scene, exit playmode and go to Assets > Easy Save 3 > Add Manager to Scene." ,
this ) ;
else
ES3AutoSaveMgr . AddAutoSave ( this ) ;
}
2025-10-03 00:02:43 -04:00
public void Reset ( )
{
// Initialise saveLayer (etc) to false for all new Components.
saveLayer = false ;
saveTag = false ;
saveName = false ;
saveHideFlags = false ;
saveActive = false ;
saveChildren = false ;
saveDestroyed = false ;
}
2026-03-20 11:56:50 -04:00
public void OnDestroy ( )
2025-10-03 00:02:43 -04:00
{
2026-03-20 11:56:50 -04:00
// If this is being destroyed, but not because the application is quitting,
// remove the AutoSave from the manager.
if ( ! isQuitting )
ES3AutoSaveMgr . DestroyAutoSave ( this ) ;
2025-10-03 00:02:43 -04:00
}
public void OnApplicationQuit ( )
{
isQuitting = true ;
}
2026-03-20 11:56:50 -04:00
public void OnBeforeSerialize ( )
2025-10-03 00:02:43 -04:00
{
}
2026-03-20 11:56:50 -04:00
2025-10-03 00:02:43 -04:00
public void OnAfterDeserialize ( )
{
// Remove any null Components
componentsToSave . RemoveAll ( c = > c = = null | | c . GetType ( ) = = typeof ( Component ) ) ;
}
}