From ff1e4698f877ead17ee723ff465f26fad58cd0a0 Mon Sep 17 00:00:00 2001 From: SmallFox <2806143047@qq.com> Date: Sun, 31 May 2026 17:42:01 +0800 Subject: 合并最新分支,重构Roll,增加了Step_Back,有点手感问题后面调 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/AnimatorHandler.cs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'Assets/Scripts/AnimatorHandler.cs') diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs index 16f0f67..775ffc4 100644 --- a/Assets/Scripts/AnimatorHandler.cs +++ b/Assets/Scripts/AnimatorHandler.cs @@ -13,11 +13,12 @@ namespace DS { [Header("绑定")] public Transform rootMotionRotation; // 将模型旋转绑定到 RootMotion - public InputHandler inputHandler; - + + [Header("组件引用")] public PlayerLocomotion playerLocomotion; // 玩家移动控制器引用,用于传递根运动数据 public Animator animator; // 动画器组件引用 + public InputHandler inputHandler; [Header("动画参数哈希")] private int _vertical; // "Vertical" 动画参数的哈希值,用于高效设置动画参数 @@ -26,6 +27,8 @@ namespace DS [Header("旋转状态")] public bool canRotate; // 是否允许角色旋转,在动画事件中控制 + + /// /// 初始化函数 - 获取 Animator 组件并计算动画参数的哈希值。 @@ -35,6 +38,8 @@ namespace DS { // 获取当前 GameObject 上的 Animator 组件 animator = GetComponent(); + inputHandler = GetComponentInParent(); + playerLocomotion = GetComponentInParent(); // 使用 Animator.StringToHash 将字符串参数名转换为整数哈希值 // 这样在 SetFloat 时使用哈希值比使用字符串更高效 @@ -117,6 +122,14 @@ namespace DS animator.SetFloat(_horizontal, h, 0.1f, Time.deltaTime); } + public void PlayerTargetAnimation(string targetAnim, bool isInteractions) + { + Debug.Log($"尝试播放动画: {targetAnim}"); + animator.applyRootMotion = isInteractions; + animator.SetBool("isInteracting",isInteractions); + animator.CrossFade(targetAnim,0.2f); + } + /// /// 触发动画的翻滚 /// @@ -157,6 +170,20 @@ namespace DS // 将根运动数据传递给 PlayerLocomotion 组件 // PlayerLocomotion 会将这些位移应用到角色控制器上 playerLocomotion.rootMotion = rootMotion; + + if (inputHandler.isInteracting == false) + { + return; + } + + //更改刚体速度方案 + // float delta = Time.deltaTime; + // playerLocomotion.rigidbody.drag = 0; + // Vector3 deltaPosition = animator.deltaPosition; + // deltaPosition.y = 0; + // Vector3 velocity = deltaPosition / delta; + // playerLocomotion.rigidbody.velocity = velocity; + } /// -- cgit