70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using UnityEngine;
|
||
using BaseGames.Combat;
|
||
|
||
namespace BaseGames.Player
|
||
{
|
||
/// <summary>
|
||
/// 武器 HitBox 实例。
|
||
/// 由 WeaponManager 在切换武器时实例化到角色的 [WeaponSocket] 子节点下,
|
||
/// 武器卸下(切换)时销毁。
|
||
///
|
||
/// Prefab 内部层级示例:
|
||
/// [WPN_SkyBlade_HitBox]
|
||
/// ├── [HitBox_Ground] ← BoxCollider2D, Layer = PlayerHitBox
|
||
/// ├── [HitBox_Up]
|
||
/// ├── [HitBox_Down]
|
||
/// └── [HitBox_Air]
|
||
///
|
||
/// 命名规范:Assets/Prefabs/Weapons/WPN_{weaponId}_HitBox.prefab
|
||
/// </summary>
|
||
public class WeaponHitBoxInstance : MonoBehaviour
|
||
{
|
||
[SerializeField] private HitBox _hitBoxGround;
|
||
[SerializeField] private HitBox _hitBoxUp;
|
||
[SerializeField] private HitBox _hitBoxDown;
|
||
[SerializeField] private HitBox _hitBoxAir;
|
||
|
||
/// <summary>下劈 HitBox 命中确认事件(供 PlayerCombat 转发给 DownAttackState pogo 逻辑)。</summary>
|
||
public event System.Action<DamageInfo> OnDownHitConfirmed;
|
||
|
||
private void Awake()
|
||
{
|
||
if (_hitBoxDown != null)
|
||
_hitBoxDown.OnHitConfirmed += info => OnDownHitConfirmed?.Invoke(info);
|
||
}
|
||
|
||
// ── 公共 API ──────────────────────────────────────────────────────────
|
||
|
||
/// <summary>激活指定方向的 HitBox。</summary>
|
||
public void Activate(AttackDirection dir, DamageSourceSO source, Transform attacker)
|
||
=> GetHitBox(dir)?.Activate(source, attacker);
|
||
|
||
/// <summary>停用指定方向的 HitBox。</summary>
|
||
public void Deactivate(AttackDirection dir)
|
||
=> GetHitBox(dir)?.Deactivate();
|
||
|
||
/// <summary>停用所有方向的 HitBox。</summary>
|
||
public void DeactivateAll()
|
||
{
|
||
_hitBoxGround?.Deactivate();
|
||
_hitBoxUp?.Deactivate();
|
||
_hitBoxDown?.Deactivate();
|
||
_hitBoxAir?.Deactivate();
|
||
}
|
||
|
||
/// <summary>切换连击段伤害源(不改变激活状态,供 PlayerCombat.SetComboSegmentSource 调用)。</summary>
|
||
public void SetDamageSource(AttackDirection dir, DamageSourceSO source)
|
||
=> GetHitBox(dir)?.SetDamageSource(source);
|
||
|
||
/// <summary>按方向查询对应 HitBox 组件。</summary>
|
||
public HitBox GetHitBox(AttackDirection dir) => dir switch
|
||
{
|
||
AttackDirection.Ground => _hitBoxGround,
|
||
AttackDirection.Up => _hitBoxUp,
|
||
AttackDirection.Down => _hitBoxDown,
|
||
AttackDirection.Air => _hitBoxAir,
|
||
_ => null,
|
||
};
|
||
}
|
||
}
|