using System.Collections; using UnityEngine; namespace BaseGames.Enemies.Abilities { /// /// 连续冲刺能力:将另一个 ChargeAbility 作为单次冲刺单元顺序触发 dashCount 次。 /// 每次冲刺之间间隔 pauseBetweenDashes 秒,每次冲刺前可重新朝向目标。 /// public sealed class MultiDashAbility : EnemyAbilityBase { [Header("冲刺单元")] [Tooltip("作为冲刺单元的 ChargeAbility 的 abilityId")] [SerializeField] private string _dashAbilityId = "charge"; [Header("节奏")] [SerializeField, Min(1)] private int _dashCount = 3; [SerializeField, Min(0f)] private float _pauseBetweenDashes = 0.25f; [SerializeField] private bool _refaceTargetEachDash = true; protected override IEnumerator ExecuteCoroutine() { if (_enemy == null) yield break; var dash = _enemy.Abilities.Get(_dashAbilityId); if (dash == null) { Debug.LogWarning($"[MultiDashAbility] 找不到冲刺单元 abilityId='{_dashAbilityId}'", this); yield break; } for (int i = 0; i < _dashCount; i++) { if (_refaceTargetEachDash && _enemy.PlayerTransform != null) FaceTarget(_enemy.PlayerTransform); // 强制执行子冲刺(连段语义,忽略冷却) if (!dash.ForceExecute()) { Debug.LogWarning($"[MultiDashAbility] ForceExecute 失败(第 {i + 1} 次)", this); yield break; } while (dash.IsRunning) yield return null; if (i < _dashCount - 1 && _pauseBetweenDashes > 0f) yield return EnemyAbilityWaits.Get(_pauseBetweenDashes); } } } }