61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using BaseGames.Combat;
|
||
|
||
namespace BaseGames.Player.States
|
||
{
|
||
/// <summary>
|
||
/// 上劈状态(架构 05_PlayerModule §2)。
|
||
/// HitBox 由 ComboStepConfig 时间窗口驱动;结束后回到 Idle(地面)或 FallState(空中)。
|
||
/// </summary>
|
||
public class UpAttackState : PlayerStateBase
|
||
{
|
||
public UpAttackState(PlayerController owner) : base(owner) { }
|
||
|
||
public override void OnStateEnter()
|
||
{
|
||
|
||
// 上劈反嵈:空中施加向下微小冲量,增强出招手感(地面无效)
|
||
if (!Move.IsGrounded && Move?.Rb != null)
|
||
Move.Rb.velocity = new UnityEngine.Vector2(Move.Rb.velocity.x, Move.Rb.velocity.y - 3f);
|
||
|
||
var step = Owner.Weapon?.ActiveWeapon?.GetDirStep(AttackDirection.Up);
|
||
float spd = Stats?.AnimatorSpeedMultiplier ?? 1f;
|
||
|
||
if (step?.clip?.Clip != null)
|
||
{
|
||
var animState = Anim.Play(step.Value.clip);
|
||
animState.Speed *= spd;
|
||
var events = animState.Events(this);
|
||
events.OnEnd = OnClipEnd;
|
||
var s = step.Value;
|
||
events.Add(s.hitBoxEnter, () => Owner.Combat?.EnableWeaponHitBox(AttackDirection.Up, s.hitBoxId));
|
||
events.Add(s.hitBoxExit, () => Owner.Combat?.DisableAllWeaponHitBoxes());
|
||
}
|
||
else
|
||
{
|
||
Owner.Combat?.EnableWeaponHitBox(AttackDirection.Up);
|
||
OnClipEnd();
|
||
}
|
||
}
|
||
|
||
public override void OnStateExit()
|
||
{
|
||
Owner.Combat?.DisableAllWeaponHitBoxes();
|
||
}
|
||
|
||
private void OnClipEnd()
|
||
{
|
||
if (Move.IsGrounded)
|
||
Owner.TransitionTo(Owner.GetState<IdleState>());
|
||
else
|
||
Owner.TransitionTo(Owner.GetState<FallState>());
|
||
}
|
||
|
||
public override void OnStateFixedUpdate()
|
||
{
|
||
// 地面上劈期间调用 Move(0) 叠加 _platformVelocity.x,使玩家随移动平台同步移动。
|
||
if (Move != null && Move.IsGrounded)
|
||
Move.Move(0f);
|
||
}
|
||
}
|
||
}
|