chore: initial commit
This commit is contained in:
58
Assets/Scripts/World/SavePoint.cs
Normal file
58
Assets/Scripts/World/SavePoint.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Events;
|
||||
using BaseGames.Core.Save;
|
||||
|
||||
namespace BaseGames.World
|
||||
{
|
||||
public class SavePoint : MonoBehaviour, IInteractable, ISaveable
|
||||
{
|
||||
[Header("Config")]
|
||||
[SerializeField] private string _savePointId;
|
||||
[SerializeField] private bool _restoreSpring = true;
|
||||
|
||||
[Header("Event Channels")]
|
||||
[SerializeField] private StringEventChannelSO _onSavePointActivated;
|
||||
[SerializeField] private VoidEventChannelSO _onFastTravelOpen;
|
||||
|
||||
private bool _isActivated;
|
||||
|
||||
// ── IInteractable ──────────────────────────────────────────────────────
|
||||
public bool CanInteract => true;
|
||||
public string InteractPrompt => _isActivated ? "休息" : "激活";
|
||||
|
||||
public void Interact(Transform player)
|
||||
{
|
||||
_isActivated = true;
|
||||
var restorer = player.GetComponentInChildren<IRestoreOnSave>();
|
||||
if (restorer != null)
|
||||
{
|
||||
restorer.FullRestore();
|
||||
if (_restoreSpring) restorer.RestoreSpring();
|
||||
}
|
||||
|
||||
_onSavePointActivated?.Raise(_savePointId);
|
||||
_onFastTravelOpen?.Raise();
|
||||
}
|
||||
|
||||
public void OnPlayerEnterRange(Transform player) { }
|
||||
public void OnPlayerExitRange() { }
|
||||
|
||||
// ── 存档集成 ────────────────────────────────────────────────────────────
|
||||
public bool IsActivated => _isActivated;
|
||||
public void SetActivated(bool val) => _isActivated = val;
|
||||
|
||||
public void OnSave(SaveData data)
|
||||
{
|
||||
if (_isActivated && !string.IsNullOrEmpty(_savePointId)
|
||||
&& !data.World.ActivatedSavePoints.Contains(_savePointId))
|
||||
data.World.ActivatedSavePoints.Add(_savePointId);
|
||||
}
|
||||
|
||||
public void OnLoad(SaveData data)
|
||||
{
|
||||
_isActivated = !string.IsNullOrEmpty(_savePointId)
|
||||
&& data.World.ActivatedSavePoints.Contains(_savePointId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user