角色能力,存档
This commit is contained in:
@@ -3,31 +3,56 @@ using UnityEngine;
|
||||
namespace BaseGames.Player.States
|
||||
{
|
||||
/// <summary>
|
||||
/// 蹬墙跳状态(架构 05_PlayerModule §2)。
|
||||
/// 从 WallSlideState 进入;施加背墙方向的水平 + 垂直速度;
|
||||
/// 短暂锁定水平输入后转为 FallState。
|
||||
/// 蹬墙跳状态(架构 05_PlayerModule §2,自定义蹬墙跳设计)。
|
||||
///
|
||||
/// 从 WallSlideState 进入(正常模式下按跳跃键触发)。
|
||||
/// 分为两种子类型,由 PrepareEnter 时的水平输入决定:
|
||||
/// - 背墙跳(Jump Away):无输入或反方向输入 → 远离墙壁斜上方弹出(WallJumpAwayForce)。
|
||||
/// - 对墙跳(Jump Toward):朝向墙壁方向输入 → 沿墙壁方向斜上方弹出(WallJumpTowardForce)。
|
||||
///
|
||||
/// 公共规则:
|
||||
/// 视为第一段跳(不消耗空中跳跃次数);支持可变高度(提前松键截断);
|
||||
/// 上升结束后转 FallState。
|
||||
/// </summary>
|
||||
public class WallJumpState : PlayerStateBase
|
||||
{
|
||||
private float _inputLockTimer;
|
||||
private int _wallDir;
|
||||
private bool _isAwayJump; // true = 背墙跳;false = 对墙跳
|
||||
|
||||
public WallJumpState(PlayerController owner) : base(owner) { }
|
||||
|
||||
/// <summary>
|
||||
/// 由 WallSlideState 在调用 TransitionTo 之前调用。
|
||||
/// wallDir:抓墙方向(+1 右墙 / -1 左墙)。
|
||||
/// moveInputX:触发跳跃时的水平输入值。
|
||||
/// </summary>
|
||||
public void PrepareEnter(int wallDir, float moveInputX)
|
||||
{
|
||||
_wallDir = wallDir;
|
||||
// 无输入或输入方向与墙壁反向 → 背墙跳;输入方向与墙壁同向 → 对墙跳
|
||||
int inputDir = moveInputX > 0.1f ? 1 : (moveInputX < -0.1f ? -1 : 0);
|
||||
_isAwayJump = (inputDir == 0 || inputDir != _wallDir);
|
||||
}
|
||||
|
||||
public override void OnStateEnter()
|
||||
{
|
||||
// 记录墙壁方向(跳跃反向)
|
||||
_wallDir = Owner.WallDetector != null ? Owner.WallDetector.WallDirection : 0;
|
||||
if (_wallDir == 0) _wallDir = -Owner.FacingDirection;
|
||||
// 施加对应类型的速度
|
||||
if (_isAwayJump)
|
||||
Move?.WallJumpAway(_wallDir);
|
||||
else
|
||||
Move?.WallJumpToward(_wallDir);
|
||||
|
||||
// 施加蹬墙跳速度
|
||||
Move?.WallJump(_wallDir);
|
||||
// 蹬墙跳视为第一段跳,重置空中跳跃次数(使二段跳可再次使用)
|
||||
Owner.ResetAirJumps();
|
||||
|
||||
// 锁定水平输入
|
||||
_inputLockTimer = Cfg.WallJumpInputLockDuration;
|
||||
|
||||
// 播放跳跃动画(复用跳跃动画)
|
||||
if (AnimCfg?.Jump != null) Anim?.Play(AnimCfg.Jump);
|
||||
// 播放蹬墙跳动画:背墙跳/对墙跳使用各自专属 Clip,留空时回退到 Jump 动画
|
||||
var wallJumpClip = _isAwayJump
|
||||
? (AnimCfg?.WallJumpAway ?? AnimCfg?.Jump)
|
||||
: (AnimCfg?.WallJumpToward ?? AnimCfg?.Jump);
|
||||
if (wallJumpClip != null) Anim?.Play(wallJumpClip);
|
||||
|
||||
Input.JumpCancelledEvent += OnJumpCancelled;
|
||||
}
|
||||
@@ -59,3 +84,4 @@ namespace BaseGames.Player.States
|
||||
private void OnJumpCancelled() => Move?.CutJump();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user