aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/AnimatorHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/AnimatorHandler.cs')
-rw-r--r--Assets/Scripts/AnimatorHandler.cs31
1 files changed, 29 insertions, 2 deletions
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; // 是否允许角色旋转,在动画事件中控制
+
+
/// <summary>
/// 初始化函数 - 获取 Animator 组件并计算动画参数的哈希值。
@@ -35,6 +38,8 @@ namespace DS
{
// 获取当前 GameObject 上的 Animator 组件
animator = GetComponent<Animator>();
+ inputHandler = GetComponentInParent<InputHandler>();
+ playerLocomotion = GetComponentInParent<PlayerLocomotion>();
// 使用 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);
+ }
+
/// <summary>
/// 触发动画的翻滚
/// </summary>
@@ -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;
+
}
/// <summary>