refactor(enemy): MeleeVulnerability 参数迁入 MeleeVulnerabilityAbilitySO(子类)
This commit is contained in:
@@ -12,44 +12,42 @@ namespace BaseGames.Enemies.Abilities
|
||||
/// </summary>
|
||||
public class MeleeVulnerabilityAbility : EnemyAbilityBase
|
||||
{
|
||||
[Header("动画")]
|
||||
[SerializeField] private ClipTransition _attackClip;
|
||||
|
||||
[Header("碰撞")]
|
||||
[SerializeField] private HitBox _hitBox;
|
||||
[SerializeField] private HurtBox _hurtBox;
|
||||
|
||||
[Header("打击时间(0~1 归一化,基于 Clip 时长)")]
|
||||
[SerializeField, Range(0f, 1f)] private float _hitEnterT = 0.30f;
|
||||
[SerializeField, Range(0f, 1f)] private float _hitExitT = 0.60f;
|
||||
private MeleeVulnerabilityAbilitySO _cfg;
|
||||
|
||||
[Header("后摇脆弱窗口")]
|
||||
[Tooltip("HurtBox 激活时间(秒)")]
|
||||
[SerializeField] private float _staggerDuration = 1.0f;
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
_cfg = ResolveConfig<MeleeVulnerabilityAbilitySO>();
|
||||
}
|
||||
|
||||
protected override IEnumerator ExecuteCoroutine()
|
||||
{
|
||||
Phase = AbilityRunState.Active;
|
||||
if (_attackClip.Clip == null) yield break;
|
||||
if (_cfg == null) yield break;
|
||||
if (_cfg.attackClip.Clip == null) yield break;
|
||||
|
||||
float len = _attackClip.Clip.length;
|
||||
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(_attackClip);
|
||||
_animancer.Play(_cfg.attackClip);
|
||||
|
||||
while (t < len)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
|
||||
if (!active && t >= len * _hitEnterT)
|
||||
if (!active && t >= len * _cfg.hitEnterT)
|
||||
{
|
||||
_hitBox?.Activate(dmgSrc, _transform);
|
||||
active = true;
|
||||
}
|
||||
if (active && t >= len * _hitExitT)
|
||||
if (active && t >= len * _cfg.hitExitT)
|
||||
{
|
||||
_hitBox?.Deactivate();
|
||||
active = false;
|
||||
@@ -65,7 +63,7 @@ namespace BaseGames.Enemies.Abilities
|
||||
if (_hurtBox != null)
|
||||
_hurtBox.enabled = true;
|
||||
|
||||
yield return EnemyAbilityWaits.Get(_staggerDuration);
|
||||
yield return EnemyAbilityWaits.Get(_cfg.staggerDuration);
|
||||
|
||||
if (_hurtBox != null)
|
||||
_hurtBox.enabled = false;
|
||||
|
||||
Reference in New Issue
Block a user