chore: initial commit
This commit is contained in:
78
Assets/Scripts/Core/DeathRespawnService.cs
Normal file
78
Assets/Scripts/Core/DeathRespawnService.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 死亡/复活流程服务接口。
|
||||
/// </summary>
|
||||
public interface IDeathRespawnService
|
||||
{
|
||||
/// <summary>玩家死亡时由 GameManager 调用,启动死亡演出流程。</summary>
|
||||
IEnumerator StartDeathSequenceCoroutine();
|
||||
|
||||
/// <summary>DeathScreen 确认按钮点击后调用,执行复活流程。</summary>
|
||||
IEnumerator StartRespawnCoroutine();
|
||||
|
||||
/// <summary>SteelSoul 模式:HP 归零后直接清档并返回主菜单。</summary>
|
||||
IEnumerator StartGameOverCoroutine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 死亡/复活流程独立服务(Phase 0 骨架,Phase 1 完整实现)。
|
||||
/// </summary>
|
||||
public class DeathRespawnService : MonoBehaviour, IDeathRespawnService
|
||||
{
|
||||
[Header("Config")]
|
||||
[SerializeField] private float _deathAnimDuration = 1.2f;
|
||||
[SerializeField] private float _deathScreenDelay = 0.5f;
|
||||
[SerializeField] private float _respawnFadeDuration = 0.4f;
|
||||
|
||||
[Header("Event Channels - Raise")]
|
||||
[SerializeField] private VoidEventChannelSO _onRespawnStarted;
|
||||
[SerializeField] private VoidEventChannelSO _onRespawnCompleted;
|
||||
|
||||
[Header("Event Channels - Listen")]
|
||||
[SerializeField] private VoidEventChannelSO _onDeathScreenConfirmed;
|
||||
|
||||
private bool _deathConfirmed;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_onDeathScreenConfirmed != null)
|
||||
_onDeathScreenConfirmed.OnEventRaised += HandleDeathScreenConfirmed;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_onDeathScreenConfirmed != null)
|
||||
_onDeathScreenConfirmed.OnEventRaised -= HandleDeathScreenConfirmed;
|
||||
}
|
||||
|
||||
private void HandleDeathScreenConfirmed() => _deathConfirmed = true;
|
||||
|
||||
public IEnumerator StartDeathSequenceCoroutine()
|
||||
{
|
||||
yield return new WaitForSeconds(_deathAnimDuration);
|
||||
yield return new WaitForSeconds(_deathScreenDelay);
|
||||
_deathConfirmed = false;
|
||||
yield return new WaitUntil(() => _deathConfirmed);
|
||||
}
|
||||
|
||||
public IEnumerator StartRespawnCoroutine()
|
||||
{
|
||||
_onRespawnStarted?.Raise();
|
||||
yield return new WaitForSeconds(_respawnFadeDuration);
|
||||
// Phase 1:加载存档场景(TODO)
|
||||
yield return new WaitForSeconds(_respawnFadeDuration);
|
||||
_onRespawnCompleted?.Raise();
|
||||
}
|
||||
|
||||
public IEnumerator StartGameOverCoroutine()
|
||||
{
|
||||
// Phase 1:SteelSoul 清档并返回主菜单(TODO)
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user