blob: 40a82f1de371f24066464654a379ac4bba251faf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 同步root motion到角色根节点
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class UnitRootMotion : MonoBehaviour
{
Transform m_Root;
Animator m_Animator;
[HideInInspector]
public bool applyToRoot = true;
private void Awake()
{
m_Root = transform.parent;
m_Animator = GetComponent<Animator>();
}
void OnAnimatorMove()
{
if (m_Animator == null)
return;
if (applyToRoot && m_Root)
{
m_Root.rotation *= m_Animator.deltaRotation;
m_Root.position += m_Animator.deltaPosition;
}
else
{
transform.rotation *= m_Animator.deltaRotation;
transform.position += m_Animator.deltaPosition;
}
}
}
|