- Added DownDash ability with cooldown and speed configuration. - Introduced DownDashState to handle down dashing mechanics, including gravity manipulation and animation playback. - Updated PlayerMovement to support DownDash functionality. - Enhanced PlayerStats to manage spring charge consumption and healing. - Modified PlayerCombat and WeaponHitBoxInstance to support new hit confirmation events. - Updated AbilityType to include new form types for character abilities. - Improved Gizmos for better visualization of enemy detection and attack ranges. - Added feedback systems for form switching in PlayerFeedback and IFeedbackPlayer. - Refactored combat and movement states to accommodate new abilities and ensure smooth transitions.
98 lines
4.0 KiB
C#
98 lines
4.0 KiB
C#
using UnityEngine;
|
||
using BaseGames.Combat;
|
||
|
||
namespace BaseGames.Player
|
||
{
|
||
/// <summary>
|
||
/// 武器 HitBox 实例。
|
||
/// 由 WeaponManager 在切换武器时实例化到角色的 [WeaponSocket] 子节点下。
|
||
///
|
||
/// Prefab 层级示例(每段连击独立一个子节点,在 Prefab 内可视化编辑 Collider2D):
|
||
/// [WPN_SkyBlade_HitBox] ← WeaponHitBoxInstance
|
||
/// ├── [HitBox_Ground] Id="" ← 方向默认(ComboStepConfig.hitBoxId 为空时使用)
|
||
/// ├── [HitBox_Ground_1] Id="g1" ← 第 1 段专属判定
|
||
/// ├── [HitBox_Ground_2] Id="g2" ← 第 2 段专属判定
|
||
/// ├── [HitBox_Up] Id="" ← 上劈默认
|
||
/// ├── [HitBox_Down] Id="" ← 下劈默认
|
||
/// └── [HitBox_Air] Id="" ← 空中默认
|
||
///
|
||
/// ComboStepConfig.hitBoxId 留空 → 用方向默认;填 Id → 精确激活对应子节点。
|
||
/// </summary>
|
||
public class WeaponHitBoxInstance : MonoBehaviour
|
||
{
|
||
[Header("方向默认 HitBox(hitBoxId 为空时使用)")]
|
||
[SerializeField] private HitBox _hitBoxGround;
|
||
[SerializeField] private HitBox _hitBoxUp;
|
||
[SerializeField] private HitBox _hitBoxDown;
|
||
[SerializeField] private HitBox _hitBoxAir;
|
||
|
||
private HitBox[] _allHitBoxes;
|
||
private AttackDirection _activeDir;
|
||
|
||
/// <summary>下劈命中确认事件(供 DownAttackState Pogo 逻辑)。</summary>
|
||
public event System.Action<DamageInfo> OnDownHitConfirmed;
|
||
|
||
/// <summary>任意 HitBox 命中确认事件(供 PlayerCombat 订阅通用命中反馈)。</summary>
|
||
public event System.Action<DamageInfo> OnHitConfirmed;
|
||
|
||
private void Awake()
|
||
{
|
||
_allHitBoxes = GetComponentsInChildren<HitBox>(true);
|
||
foreach (var hb in _allHitBoxes)
|
||
hb.OnHitConfirmed += OnAnyHitConfirmed;
|
||
}
|
||
|
||
private void OnAnyHitConfirmed(DamageInfo info)
|
||
{
|
||
OnHitConfirmed?.Invoke(info);
|
||
if (_activeDir == AttackDirection.Down)
|
||
OnDownHitConfirmed?.Invoke(info);
|
||
}
|
||
|
||
// ── 公共 API ──────────────────────────────────────────────────────────
|
||
|
||
/// <summary>
|
||
/// 激活 HitBox。
|
||
/// hitBoxId 非空时按 Id 精确查找 Prefab 子节点;空 = 使用该方向的默认 HitBox。
|
||
/// </summary>
|
||
public void Activate(AttackDirection dir, DamageSourceSO source, Transform attacker,
|
||
string hitBoxId = "")
|
||
{
|
||
_activeDir = dir;
|
||
var hitBox = string.IsNullOrEmpty(hitBoxId)
|
||
? GetHitBox(dir)
|
||
: (GetHitBoxById(hitBoxId) ?? GetHitBox(dir));
|
||
hitBox?.Activate(source, attacker);
|
||
}
|
||
|
||
/// <summary>停用指定方向的默认 HitBox。</summary>
|
||
public void Deactivate(AttackDirection dir) => GetHitBox(dir)?.Deactivate();
|
||
|
||
/// <summary>停用 Prefab 中所有 HitBox。</summary>
|
||
public void DeactivateAll()
|
||
{
|
||
if (_allHitBoxes == null) return;
|
||
foreach (var hb in _allHitBoxes) hb.Deactivate();
|
||
}
|
||
|
||
/// <summary>按 HitBox.Id 查找子节点(未找到返回 null)。</summary>
|
||
public HitBox GetHitBoxById(string id)
|
||
{
|
||
if (_allHitBoxes == null || string.IsNullOrEmpty(id)) return null;
|
||
foreach (var hb in _allHitBoxes)
|
||
if (hb.Id == id) return hb;
|
||
return null;
|
||
}
|
||
|
||
/// <summary>按攻击方向返回默认 HitBox。</summary>
|
||
public HitBox GetHitBox(AttackDirection dir) => dir switch
|
||
{
|
||
AttackDirection.Ground => _hitBoxGround,
|
||
AttackDirection.Up => _hitBoxUp,
|
||
AttackDirection.Down => _hitBoxDown,
|
||
AttackDirection.Air => _hitBoxAir,
|
||
_ => null,
|
||
};
|
||
}
|
||
}
|