80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using System.Collections;
|
|
using Animancer;
|
|
using BaseGames.Combat;
|
|
using UnityEngine;
|
|
|
|
namespace BaseGames.Enemies.Abilities
|
|
{
|
|
/// <summary>
|
|
/// 近战攻击带后摇脆弱窗口能力:攻击动画期间按时间比例激活 HitBox,
|
|
/// 攻击完成后开放 HurtBox(脆弱窗口),窗口结束后恢复正常。
|
|
/// 可复用于任何"攻击后有反击窗口"的敌人技能。
|
|
/// </summary>
|
|
public class MeleeVulnerabilityAbility : EnemyAbilityBase
|
|
{
|
|
[Header("碰撞")]
|
|
[SerializeField] private HitBox _hitBox;
|
|
[SerializeField] private HurtBox _hurtBox;
|
|
|
|
private MeleeVulnerabilityAbilitySO _cfg;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
_cfg = ResolveConfig<MeleeVulnerabilityAbilitySO>();
|
|
}
|
|
|
|
protected override IEnumerator ExecuteCoroutine()
|
|
{
|
|
Phase = AbilityRunState.Active;
|
|
if (_cfg == null) yield break;
|
|
if (_cfg.attackClip.Clip == null) yield break;
|
|
|
|
float len = _cfg.attackClip.Clip.length;
|
|
float t = 0f;
|
|
bool active = false;
|
|
|
|
var dmgSrc = _config?.attackSequence?.Length > 0 ? _config.attackSequence[0].damageSource : null;
|
|
|
|
_animancer.Play(_cfg.attackClip);
|
|
|
|
while (t < len)
|
|
{
|
|
t += Time.deltaTime;
|
|
|
|
if (!active && t >= len * _cfg.hitEnterT)
|
|
{
|
|
_hitBox?.Activate(dmgSrc, _transform);
|
|
active = true;
|
|
}
|
|
if (active && t >= len * _cfg.hitExitT)
|
|
{
|
|
_hitBox?.Deactivate();
|
|
active = false;
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
|
|
if (active)
|
|
_hitBox?.Deactivate();
|
|
|
|
// 后摇脆弱窗口
|
|
if (_hurtBox != null)
|
|
_hurtBox.enabled = true;
|
|
|
|
yield return EnemyAbilityWaits.Get(_cfg.staggerDuration);
|
|
|
|
if (_hurtBox != null)
|
|
_hurtBox.enabled = false;
|
|
}
|
|
|
|
protected override void OnInterrupted(InterruptReason reason)
|
|
{
|
|
_hitBox?.Deactivate();
|
|
if (_hurtBox != null)
|
|
_hurtBox.enabled = false;
|
|
}
|
|
}
|
|
}
|