using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using PixelCrushers; using PixelCrushers.DialogueSystem; using PixelCrushers.QuestMachine.DialogueSystemSupport; using UnityEngine; using UnityEngine.SceneManagement; namespace Beyond { [RequireComponent(typeof(Collider))] public class CheckpointSaver : Saver { public Transform m_spawnPoint; [Serializable] public class Data { public bool wasTriggered = false; } private Data m_data = new Data(); void Awake() { m_data = new Data(); m_data.wasTriggered = false; var collider = GetComponent(); collider.gameObject.layer = LayerMask.NameToLayer("Triggers"); } private void OnTriggerEnter(Collider other) { if (!m_data.wasTriggered && other.gameObject.tag == "Player") { Player.Instance.OnCheckpoint(); SaveUtility.Instance.SaveCheckpoint(); m_data.wasTriggered = true; } } public override string RecordData() { return SaveSystem.Serialize(m_data); } public override void ApplyData(string data) { m_data = SaveSystem.Deserialize(data); if (m_data == null) m_data = new Data(); } //public override void ApplyDataImmediate() //{ // // If your Saver needs to pull data from the Save System immediately after // // loading a scene, instead of waiting for ApplyData to be called at its // // normal time, which may be some number of frames after the scene has started, // // it can implement this method. For efficiency, the Save System will not look up // // the Saver's data; your method must look it up manually by calling // // SaveSystem.savedGameData.GetData(key). //} public override void OnBeforeSceneChange() { // The Save System will call this method before scene changes. If your saver listens for // OnDisable or OnDestroy messages (see DestructibleSaver for example), it can use this // method to ignore the next OnDisable or OnDestroy message since they will be called // because the entire scene is being unloaded. } //public override void OnRestartGame() //{ // // The Save System will call this method when restarting the game from the beginning. // // Your Saver can reset things to a fresh state if necessary. //} } }