using System.Collections; using UnityEngine; using BaseGames.Core; using BaseGames.Core.Pool; namespace BaseGames.Enemies.Boss.Patterns { /// /// 攻击预警系统(架构 07_EnemyModule §11)。 /// 在攻击前若干帧显示视觉提示(VFX 从对象池取出,到期归还)。 /// 由 BD_TelegraphAttack 通过协程调用 ShowTelegraph。 /// public class TelegraphSystem : MonoBehaviour { /// /// 开始预警:从对象池取出 vfxKey 对应预警 VFX,等待 duration 秒后归还。 /// 由 BD_TelegraphAttack.OnStart 通过 StartCoroutine 调用。 /// 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(); 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(); if (po != null) po.ReturnToPool(); else vfx.SetActive(false); } } /// 立即隐藏所有活跃预警 VFX(技能被打断时调用)。 public void CancelTelegraph() { StopAllCoroutines(); } } }