Files
zeling_v2/Assets/_Game/Scripts/Player/States/HurtState.cs
Joywayer 09bdda970a 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>
2026-06-12 11:48:37 +08:00

67 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BaseGames.Combat;
namespace BaseGames.Player.States
{
/// <summary>
/// 受击硬直状态(架构 05_PlayerModule §2
/// 由 PlayerController.TakeDamage 在玩家非无敌时触发;
/// 播放 Hurt 动画,施加击退,结束后回到 Idle 或 Fall。
/// </summary>
public class HurtState : PlayerStateBase
{
private float _timer;
private bool _ended;
private Vector3 _hitPoint;
public HurtState(PlayerController owner) : base(owner) { }
public void Initialize(BaseGames.Combat.DamageInfo info)
{
// 由 PlayerController.TakeDamage 传入伤害信息
_hitPoint = info.HitPoint;
if (info.KnockbackForce > 0.01f)
Move?.ApplyKnockback(info.KnockbackDirection, info.KnockbackForce);
}
public override void OnStateEnter()
{
// 持续时长从 PlayerAnimationConfigSO 读取,不同攻击可设置不同硬直
_timer = Owner.AnimConfig?.HurtDuration ?? 0.4f;
_ended = false;
Stats?.BeginInvincibility();
Feedback.PlayTakeHit(_hitPoint);
if (AnimCfg?.Hurt != null)
{
var state = Anim?.Play(AnimCfg.Hurt);
if (state != null)
state.Events(this).OnEnd = OnHurtEnd;
}
}
public override void OnStateUpdate()
{
_timer -= Time.deltaTime;
if (_timer <= 0f)
OnHurtEnd();
}
private void OnHurtEnd()
{
if (_ended) return;
_ended = true;
if (Stats != null && !Stats.IsAlive)
{
Owner.TransitionTo(Owner.GetState<DeadState>());
return;
}
if (Move.IsGrounded)
Owner.TransitionTo(Owner.GetState<IdleState>());
else
Owner.TransitionTo(Owner.GetState<FallState>());
}
}
}