feat(feedback): 命中/受击反馈支持固定位置与击中位置两种生成模式

DamageInfo 新增运行时字段 HitPoint:HitBox 结算时写入精确接触点
(ClosestPoint),HurtBox.ReceiveDamage 以解析后命中点兜底盖戳,
陷阱/环境等直调路径同样可用。IFeedbackPlayer.PlayHit/PlayTakeHit
增加命中点参数,全链路(武器实例→PlayerCombat→HurtState→
EnemyFeedback)透传。各 Feedback 组件命中/受击槽位新增
FeedbackPositionMode(Fixed=反馈链编排的固定位置 /
HitPoint=传入命中点,启用位置选项的模块在该点生成),由编排
反馈链的开发者在 Inspector 按表现选择;武器命中默认 HitPoint
(火花贴点),角色级默认 Fixed(震屏/振动与位置无关)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 11:48:37 +08:00
parent 5ccab35948
commit 09bdda970a
10 changed files with 93 additions and 29 deletions

View File

@@ -34,6 +34,13 @@ namespace BaseGames.Combat
/// </summary>
[System.NonSerialized] public uint HitActivationId;
/// <summary>
/// 命中点世界坐标。HitBox 结算时写入精确接触点ClosestPoint
/// 直接调用 HurtBox.ReceiveDamage 的路径由 HurtBox 以解析后的命中点兜底写入。
/// 供"击中位置"模式的反馈在该点生成FeedbackPositionMode.HitPoint
/// [NonSerialized]:运行时逐次命中生成,不需要序列化。
/// </summary>
[System.NonSerialized] public Vector3 HitPoint;
/// <summary>
/// 攻击来源投射物(仅当攻击方是 Projectile 时非 null
/// 用于弹反成功时调用 ReflectBy(parrier) 按弹反者阵营反射(玩家弹反才翻转阵营)。
/// [NonSerialized]MonoBehaviour 引用不参与 Unity 资产序列化。

View File

@@ -268,15 +268,18 @@ namespace BaseGames.Combat
_ownerProjectile);
info.HitActivationId = _currentActivationId;
// hitPoint优先使用触发命中的碰撞体中心在目标表面的最近点
// 无 sourceCollider直属碰撞体时回退到 HitBox 节点坐标。
// 写入 info.HitPoint 供下游"击中位置"模式的反馈在该点生成。
Vector2 hitOrigin = sourceCollider != null
? (Vector2)sourceCollider.bounds.center
: (Vector2)transform.position;
Vector3 hitPoint = other.ClosestPoint(hitOrigin);
info.HitPoint = hitPoint;
// ② 命中 HurtBox
if (other.TryGetComponent<HurtBox>(out var hurtBox))
{
// hitPoint优先使用触发命中的碰撞体中心在 HurtBox 表面的最近点;
// 无 sourceCollider直属碰撞体时回退到 HitBox 节点坐标。
Vector2 hitOrigin = sourceCollider != null
? (Vector2)sourceCollider.bounds.center
: (Vector2)transform.position;
Vector3 hitPoint = other.ClosestPoint(hitOrigin);
hurtBox.ReceiveDamage(info, hitPoint);
OnHitConfirmed?.Invoke(info);
return;

View File

@@ -61,6 +61,9 @@ namespace BaseGames.Combat
public void ReceiveDamage(DamageInfo info, Vector3? hitPoint = null)
{
Vector3 resolvedHitPoint = hitPoint ?? transform.position;
// 兜底盖戳:直接调用本方法的路径(陷阱/环境伤害)没有 HitBox 写入的精确接触点,
// 统一以解析后的命中点填充,保证下游"击中位置"模式反馈始终有效
info.HitPoint = resolvedHitPoint;
if (!_isActive || _owner == null) return;
// 所有者级去重:同一 HitBox 激活期内多个 HurtBox 子节点只处理首次命中(共享 HP
if (_ownerGuard != null && !_ownerGuard.TryRegisterHit(info.HitActivationId)) return;