refactor(enemy): MeleeVulnerability 参数迁入 MeleeVulnerabilityAbilitySO(子类)
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using Animancer;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Enemies.Abilities
|
||||
{
|
||||
/// <summary>MeleeVulnerabilityAbility 的配置:攻击动画 + 打击归一化时机 + 后摇脆弱时长。</summary>
|
||||
[CreateAssetMenu(menuName = "BaseGames/Enemies/Abilities/Melee Vulnerability Ability", fileName = "ABL_")]
|
||||
public class MeleeVulnerabilityAbilitySO : EnemyAbilitySO
|
||||
{
|
||||
[Header("动画")]
|
||||
public ClipTransition attackClip;
|
||||
|
||||
[Header("打击时间(0~1 归一化,基于 Clip 时长)")]
|
||||
[Range(0f, 1f)] public float hitEnterT = 0.30f;
|
||||
[Range(0f, 1f)] public float hitExitT = 0.60f;
|
||||
|
||||
[Header("后摇脆弱窗口")]
|
||||
[Tooltip("HurtBox 激活时间(秒)")]
|
||||
public float staggerDuration = 1.0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6232abd0bfcd744399d2fcc13db33f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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