chore: initial commit
This commit is contained in:
38
Assets/Scripts/Player/States/JumpState.cs
Normal file
38
Assets/Scripts/Player/States/JumpState.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Player.States
|
||||
{
|
||||
/// <summary>跳跃状态。在 OnStateEnter 触发跳跃,速度降为零时转为 FallState。</summary>
|
||||
public class JumpState : PlayerStateBase
|
||||
{
|
||||
public JumpState(PlayerController owner) : base(owner) { }
|
||||
|
||||
public override void OnStateEnter()
|
||||
{
|
||||
if (AnimCfg?.Jump != null)
|
||||
Anim.Play(AnimCfg.Jump);
|
||||
Move.Jump();
|
||||
Input.JumpCancelledEvent += OnJumpCancelled;
|
||||
}
|
||||
|
||||
public override void OnStateUpdate()
|
||||
{
|
||||
// 上升结束时转为下落
|
||||
if (Move.Rb.velocity.y <= 0f)
|
||||
{
|
||||
_owner.TransitionTo(_owner.FallState);
|
||||
return;
|
||||
}
|
||||
// 水平移动
|
||||
if (Mathf.Abs(Input.MoveInput.x) > 0.01f)
|
||||
Move.Move(Input.MoveInput.x * (Cfg != null ? Cfg.RunSpeed : 7f));
|
||||
}
|
||||
|
||||
public override void OnStateExit()
|
||||
{
|
||||
Input.JumpCancelledEvent -= OnJumpCancelled;
|
||||
}
|
||||
|
||||
private void OnJumpCancelled() => Move.CutJump();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user