using UnityEngine; using BaseGames.Core.Events; namespace BaseGames.World { /// /// 死亡遗骸(Death Shade)。玩家死亡时在死亡地点留下遗骸, /// 再次到达并交互后回收存储的 Geo。 /// 实现 接口以接入通用交互系统。 /// public class DeathShade : MonoBehaviour, IInteractable { [SerializeField] private IntEventChannelSO _onGeoRecovered; [SerializeField] private StringEventChannelSO _onShadeCollected; private int _storedGeo; private string _sceneId; // ── IInteractable ──────────────────────────────────────────────── public bool CanInteract => true; public string InteractPrompt => "回收遗骸"; /// /// 由死亡系统调用:设定存储 Geo 数量、所在场景 ID,并移动到死亡坐标。 /// public void Initialize(int geo, string sceneId, Vector2 position) { _storedGeo = geo; _sceneId = sceneId; transform.position = position; } public void OnPlayerEnterRange(Transform player) { } public void OnPlayerExitRange() { } /// /// 玩家交互:广播 Geo 回收事件和场景标记,然后销毁自身。 /// PlayerStats 订阅 _onGeoRecovered 事件并自行添加 Geo,保持零耦合。 /// public void Interact(Transform player) { if (_storedGeo > 0) _onGeoRecovered?.Raise(_storedGeo); _onShadeCollected?.Raise(_sceneId); Destroy(gameObject); } } }