From 364bd0db3dba9a0cc80f76cb465d80209922557f Mon Sep 17 00:00:00 2001 From: SmallFox <2806143047@qq.com> Date: Tue, 2 Jun 2026 20:02:14 +0800 Subject: 小写一点 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Art/Animator/Humanoid.controller | 12 +++++++++-- Assets/Scripts/AnimatorHandler.cs | 3 ++- Assets/Scripts/InputHandler.cs | 16 +++------------ Assets/Scripts/PlayerLocomotion.cs | 14 ++----------- Assets/Scripts/PlayerManager.cs | 36 ++++++++++++++++++++++++++++++++- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/Assets/Art/Animator/Humanoid.controller b/Assets/Art/Animator/Humanoid.controller index 08c01eb..bf9171d 100644 --- a/Assets/Art/Animator/Humanoid.controller +++ b/Assets/Art/Animator/Humanoid.controller @@ -132,7 +132,7 @@ BlendTree: m_Mirror: 0 - serializedVersion: 2 m_Motion: {fileID: 7400000, guid: 7e06266474a66574b90ac02b4ddb5d23, type: 2} - m_Threshold: 0.5 + m_Threshold: 0.33333334 m_Position: {x: 0, y: 0.5} m_TimeScale: 1 m_CycleOffset: 0 @@ -140,12 +140,20 @@ BlendTree: m_Mirror: 0 - serializedVersion: 2 m_Motion: {fileID: 7400000, guid: 856de0caf3ae81743995684fd43e0d25, type: 2} - m_Threshold: 1 + m_Threshold: 0.6666667 m_Position: {x: 0, y: 1} m_TimeScale: 1 m_CycleOffset: 0 m_DirectBlendParameter: Vertical m_Mirror: 0 + - serializedVersion: 2 + m_Motion: {fileID: 7400000, guid: 9b4dd051a907bce43ac63469232d3a92, type: 2} + m_Threshold: 1 + m_Position: {x: 0, y: 2} + m_TimeScale: 1 + m_CycleOffset: 0 + m_DirectBlendParameter: Vertical + m_Mirror: 0 m_BlendParameter: Horizontal m_BlendParameterY: Vertical m_MinThreshold: 0 diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs index 157b78f..91c782e 100644 --- a/Assets/Scripts/AnimatorHandler.cs +++ b/Assets/Scripts/AnimatorHandler.cs @@ -19,6 +19,7 @@ namespace DS public PlayerLocomotion playerLocomotion; // 玩家移动控制器引用,用于传递根运动数据 public Animator animator; // 动画器组件引用 public InputHandler inputHandler; + public PlayerManager playerManager; [Header("动画参数哈希")] private int _vertical; // "Vertical" 动画参数的哈希值,用于高效设置动画参数 @@ -177,7 +178,7 @@ namespace DS // PlayerLocomotion 会将这些位移应用到角色控制器上 playerLocomotion.rootMotion = rootMotion; - if (inputHandler.isInteracting == false) + if (playerManager.isInteracting == false) { return; } diff --git a/Assets/Scripts/InputHandler.cs b/Assets/Scripts/InputHandler.cs index 9f57c20..4ddc48a 100644 --- a/Assets/Scripts/InputHandler.cs +++ b/Assets/Scripts/InputHandler.cs @@ -32,7 +32,6 @@ namespace DS public bool rollFlag; public bool sprintFlag; public float rollInputTimer; - public bool isInteracting; [Header("其他操作输入")] [Tooltip("翻滚是否触发")] @@ -40,7 +39,7 @@ namespace DS // ===== 私有引用与输入缓存 ===== private PlayerControls _inputActions; // 新输入系统生成的 PlayerControls 实例 - private CameraHandler _cameraHandler; // 相机处理器单例引用 + private Vector2 _movementInput; // 缓存移动输入值 (x => 水平, y => 垂直) private Vector2 _cameraInput; // 缓存视角输入值 (x => 水平视角, y => 垂直视角) @@ -49,8 +48,7 @@ namespace DS private void Start() { - // 获取相机处理器的单例引用,用于在 FixedUpdate 中驱动相机跟随与旋转 - _cameraHandler = CameraHandler.singleton; + } /// @@ -58,15 +56,7 @@ namespace DS /// private void FixedUpdate() { - float delta = Time.fixedDeltaTime; // 固定时间步长,确保物理一致性 - - if (_cameraHandler != null) - { - // 让相机跟随目标(通常是玩家角色) - _cameraHandler.FollowTarget(delta); - // 根据鼠标/摇杆输入旋转相机 - _cameraHandler.HandleCameraRotation(delta, mouseX, mouseY); - } + } /// diff --git a/Assets/Scripts/PlayerLocomotion.cs b/Assets/Scripts/PlayerLocomotion.cs index e94099b..d513899 100644 --- a/Assets/Scripts/PlayerLocomotion.cs +++ b/Assets/Scripts/PlayerLocomotion.cs @@ -112,14 +112,7 @@ namespace DS // ============================================================ // 每帧更新(使用 Update 处理移动逻辑,因为需要与输入同步) // ============================================================ - private void Update() - { - float delta = Time.deltaTime; // 获取帧时间 - isSprinting = _inputHandler.b_Input; - UpdateCharacterMovement(delta); - HandleRollingAndSpringting(delta); - } // ============================================================ // 固定更新(当前未使用,但保留以备未来物理相关逻辑) @@ -177,14 +170,11 @@ namespace DS // ============================================================ // 角色移动更新(核心逻辑) // ============================================================ - private void UpdateCharacterMovement(float delta) + public void UpdateCharacterMovement(float delta) { if (_inputHandler.rollFlag) return; - // 处理输入(读取水平/垂直输入值) - _inputHandler.TickInput(delta); - // ---------------------------------------------------------- // 1. 计算移动方向(基于摄像机朝向) // ---------------------------------------------------------- @@ -252,7 +242,7 @@ namespace DS } } - private void HandleRollingAndSpringting(float delta) + public void HandleRollingAndSpringting(float delta) { if (animatorHandler.animator.GetBool("isInteracting")) { diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index e80c0a2..25b16f0 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -8,17 +8,51 @@ public class PlayerManager : MonoBehaviour { private InputHandler _inputHandler; private Animator _animator; + + public bool isInteracting; + private CameraHandler _cameraHandler; // 相机处理器单例引用 + private PlayerLocomotion _playerLocomotion; + + + private void Awake() + { + // 获取相机处理器的单例引用,用于在 FixedUpdate 中驱动相机跟随与旋转 + _cameraHandler = CameraHandler.singleton; + } private void Start() { _inputHandler = GetComponent(); _animator = GetComponentInChildren(); + _playerLocomotion = GetComponent(); } private void Update() { - _inputHandler.isInteracting = _animator.GetBool("isInteracting"); + float delta = Time.deltaTime; + + isInteracting = _animator.GetBool("isInteracting"); _inputHandler.rollFlag = false; _inputHandler.sprintFlag = false; + + _playerLocomotion.isSprinting = _inputHandler.b_Input; + // 处理输入(读取水平/垂直输入值) + _inputHandler.TickInput(delta); + _playerLocomotion.UpdateCharacterMovement(delta); + _playerLocomotion.HandleRollingAndSpringting(delta); + + } + + private void FixedUpdate() + { + float delta = Time.fixedDeltaTime; // 固定时间步长,确保物理一致性 + + if (_cameraHandler != null) + { + // 让相机跟随目标(通常是玩家角色) + _cameraHandler.FollowTarget(delta); + // 根据鼠标/摇杆输入旋转相机 + _cameraHandler.HandleCameraRotation(delta, _inputHandler.mouseX,_inputHandler.mouseY); + } } } -- cgit