chore: initial commit
This commit is contained in:
51
Assets/Scripts/Core/Save/EmergencySaveService.cs
Normal file
51
Assets/Scripts/Core/Save/EmergencySaveService.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Core.Save
|
||||
{
|
||||
public class EmergencySaveService : MonoBehaviour
|
||||
{
|
||||
private const int EmergencySlot = 99;
|
||||
|
||||
[SerializeField] private float _intervalSeconds = 120f;
|
||||
[SerializeField] private SaveManager _saveManager;
|
||||
[SerializeField] private BoolEventChannelSO _onGameplayActive;
|
||||
|
||||
private bool _gameplayActive;
|
||||
private float _timer;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_onGameplayActive != null) _onGameplayActive.OnEventRaised += OnGameplayActiveChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_onGameplayActive != null) _onGameplayActive.OnEventRaised -= OnGameplayActiveChanged;
|
||||
}
|
||||
|
||||
private void OnGameplayActiveChanged(bool value) => _gameplayActive = value;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_gameplayActive || _saveManager == null) return;
|
||||
_timer += Time.deltaTime;
|
||||
if (_timer >= _intervalSeconds)
|
||||
{
|
||||
_timer = 0f;
|
||||
_ = _saveManager.SaveAsync(EmergencySlot);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasEmergencySave()
|
||||
=> _saveManager != null && _saveManager.SlotExists(EmergencySlot);
|
||||
|
||||
public async Task PromoteToSlot(int targetSlot)
|
||||
{
|
||||
if (_saveManager == null) return;
|
||||
// Phase 1 stub:完整实现在 Phase 2 LocalFileStorage API
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user