Files
zeling_v2/Assets/Scripts/World/DeathShade.cs
2026-05-12 15:34:08 +08:00

51 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BaseGames.Core.Events;
namespace BaseGames.World
{
/// <summary>
/// 死亡遗骸Death Shade。玩家死亡时在死亡地点留下遗骸
/// 再次到达并交互后回收存储的 Geo。
/// 实现 <see cref="IInteractable"/> 接口以接入通用交互系统。
/// </summary>
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 => "回收遗骸";
/// <summary>
/// 由死亡系统调用:设定存储 Geo 数量、所在场景 ID并移动到死亡坐标。
/// </summary>
public void Initialize(int geo, string sceneId, Vector2 position)
{
_storedGeo = geo;
_sceneId = sceneId;
transform.position = position;
}
public void OnPlayerEnterRange(Transform player) { }
public void OnPlayerExitRange() { }
/// <summary>
/// 玩家交互:广播 Geo 回收事件和场景标记,然后销毁自身。
/// PlayerStats 订阅 _onGeoRecovered 事件并自行添加 Geo保持零耦合。
/// </summary>
public void Interact(Transform player)
{
if (_storedGeo > 0)
_onGeoRecovered?.Raise(_storedGeo);
_onShadeCollected?.Raise(_sceneId);
Destroy(gameObject);
}
}
}