Files
zeling_v2/Assets/_Game/Scripts/Enemies/Boss/Patterns/TelegraphSystem.cs

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 System.Collections;
using UnityEngine;
using BaseGames.Core;
using BaseGames.Core.Pool;
namespace BaseGames.Enemies.Boss.Patterns
{
/// <summary>
/// 攻击预警系统(架构 07_EnemyModule §11
/// 在攻击前若干帧显示视觉提示VFX 从对象池取出,到期归还)。
/// 由 BD_TelegraphAttack 通过协程调用 ShowTelegraph。
/// </summary>
public class TelegraphSystem : MonoBehaviour
{
/// <summary>
/// 开始预警:从对象池取出 vfxKey 对应预警 VFX等待 duration 秒后归还。
/// 由 BD_TelegraphAttack.OnStart 通过 StartCoroutine 调用。
/// </summary>
public IEnumerator ShowTelegraph(string vfxKey, float duration, Vector2 position)
{
if (string.IsNullOrEmpty(vfxKey) || duration <= 0f)
{
yield return null;
yield break;
}
GameObject vfx = null;
var pool = ServiceLocator.GetOrDefault<IObjectPoolService>();
if (pool != null)
vfx = pool.Spawn(vfxKey, new Vector3(position.x, position.y, 0f), Quaternion.identity);
else
Debug.LogWarning($"[TelegraphSystem] IObjectPoolService 未就绪,预警 VFX '{vfxKey}' 无法显示。");
yield return new WaitForSeconds(duration);
if (vfx != null && pool != null)
{
var po = vfx.GetComponent<PooledObject>();
if (po != null) po.ReturnToPool();
else vfx.SetActive(false);
}
}
/// <summary>立即隐藏所有活跃预警 VFX技能被打断时调用。</summary>
public void CancelTelegraph()
{
StopAllCoroutines();
}
}
}