blob: 90e4a7e08841e8262d4904d1485bd19a6013dd94 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public partial class SaionjiScript : Avatar
{
HitBoxTest hitbox;
Animator animator;
public GameObject Go_PistolL;
public GameObject Go_PistolR;
public GameObject Go_Blade;
public bool UsePistol;
public bool UseBlade;
public bool EnableAbilitySystem;
public EffectHandler[] Effects;
// Start is called before the first frame update
void Start()
{
base.Init();
animator = GetComponent<Animator>();
//animator.speed = 0;
PhysicsWorld.Instance.AddAnimator(animator);
Go_PistolL.SetActive(UsePistol);
Go_PistolR.SetActive(UsePistol);
Go_Blade.SetActive(UseBlade);
GetAnimHash();
if (EnableAbilitySystem)
SetupAbilities();
}
//private void Update()
//{
// //if (EnableAbilitySystem)
// // m_AbilitySystem.OnUpdate();
//}
// 更新顺序:
// internal animator update -> OnAnimatorMove() -> physics
// 角色最后的位置以物理系统为准(如果加入物理系统的话)
// 如果后续有物理处理,会重写transform
// 对于后续不受物理管理的动作,不需要修改transform
void OnAnimatorMove()
{
Animator animator = GetComponent<Animator>();
if (animator == null)
return;
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if(stateInfo.IsTag("IgnoreRootMotion"))
{
// ignore root motion
//Debug.Log("ignore root motion ");
}
else
{
// animator.deltaPosition和animator.deltaRotation是animator做的root motion后的结果
// 在后面做一个硬性约束z=0,将角色限制在z=0平面上
Vector3 position = transform.position;
position.x += animator.deltaPosition.x;
position.y += animator.deltaPosition.y;
transform.position = position;
// animation clip导入设置旋转一般上设置为baked inpose,不需要手动限制
transform.rotation *= animator.deltaRotation;
}
}
}
|