- 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.
63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using UnityEngine;
|
||
|
||
namespace BaseGames.Player.States
|
||
{
|
||
/// <summary>
|
||
/// 向下冲刺状态(空中下 + 冲刺触发)。
|
||
/// - 消耗空中冲刺次数(与普通冲刺共享,本次离地仅可用一次)。
|
||
/// - 关闭重力,施加向下速度,持续 DownDashDuration 秒。
|
||
/// - 提前着地或计时结束时退出。
|
||
/// - 需解锁 AbilityType.DownDash 才能进入(FallState / JumpState 负责条件检查)。
|
||
/// </summary>
|
||
public class DownDashState : PlayerStateBase
|
||
{
|
||
private float _timer;
|
||
|
||
public DownDashState(PlayerController owner) : base(owner) { }
|
||
|
||
public override void OnStateEnter()
|
||
{
|
||
// 消耗空中冲刺次数(与普通空中冲刺互斥)
|
||
Owner.GetState<DashState>()?.ConsumeAirDashCharge();
|
||
|
||
_timer = Cfg.DownDashDuration;
|
||
|
||
// 关闭重力,施加向下速度
|
||
Move?.SetGravityScale(0f);
|
||
Move?.DownDash(Cfg.DownDashSpeed);
|
||
|
||
// 优先播放专属动画,未配置时回退到 Fall 动画
|
||
var clip = AnimCfg?.DownDash ?? AnimCfg?.Fall;
|
||
if (clip != null) Anim?.Play(clip);
|
||
}
|
||
|
||
public override void OnStateUpdate()
|
||
{
|
||
_timer -= Time.deltaTime;
|
||
if (_timer <= 0f || Move.IsGrounded)
|
||
EndDownDash();
|
||
}
|
||
|
||
public override void OnStateFixedUpdate()
|
||
{
|
||
// 持续保持向下速度(防止摩擦力减速)
|
||
if (_timer > 0f && !Move.IsGrounded)
|
||
Move?.DownDash(Cfg.DownDashSpeed);
|
||
}
|
||
|
||
public override void OnStateExit()
|
||
{
|
||
Move?.SetGravityScale(Cfg.DefaultGravityScale);
|
||
}
|
||
|
||
private void EndDownDash()
|
||
{
|
||
Move?.ZeroVelocity();
|
||
if (Move != null && Move.IsGrounded)
|
||
Owner.TransitionTo(Owner.GetState<IdleState>());
|
||
else
|
||
Owner.TransitionTo(Owner.GetState<FallState>());
|
||
}
|
||
}
|
||
}
|