-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAnimationPlayer.cs
More file actions
144 lines (117 loc) · 3.32 KB
/
AnimationPlayer.cs
File metadata and controls
144 lines (117 loc) · 3.32 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public partial class AnimationPlayer : AnimationPlayerBase
{
public AnimationState GetState(string stateName)
{
return _states[_GetStateIndex(stateName)];
}
public AnimationState GetState(int index)
{
if (!IsStateIndexValid(index))
return null;
return _states[index];
}
public int AddState(string stateName, AnimationClip animClip)
{
return _AddState(stateName, animClip);
}
public void RemoveState(string stateName)
{
_RemoveState(_GetStateIndex(stateName));
}
public void RemoveState(int index)
{
_RemoveState(index);
}
public void Play(string stateName)
{
Play(_GetStateIndex(stateName));
}
public void Play(int index)
{
if (!IsStateIndexValid(index))
return;
if (!_graph.IsPlaying())
Play();
CurStateIndex = index;
for (int i = 0; i < _states.Length; i++) {
AnimationState state = _states[i];
if (state == null)
continue;
state.SetEnable(i == index ? true : false);
state.SetWeight(i == index ? 1.0f : 0.0f);
state.ResetFade();
}
}
public void CrossFade(string stateName, float fadeTime)
{
CrossFade(_GetStateIndex(stateName), fadeTime);
}
public void CrossFade(int index, float fadeTime)
{
if (!IsStateIndexValid(index))
return;
if (!_graph.IsPlaying())
Play();
CurStateIndex = index;
_states[index].SetEnable(true);
for (int i = 0; i < _states.Length; i++) {
AnimationState state = _states[i];
if (state == null)
continue;
if (state.enable == false)
continue;
float targetWeight = i == index ? 1.0f : 0.0f;
state.SetFade(targetWeight, fadeTime);
}
}
public void Blend(string stateName, float targetWeight, float fadeTime)
{
Blend(_GetStateIndex(stateName), targetWeight, fadeTime);
}
public void Blend(int index, float targetWeight, float fadeTime)
{
if (!IsStateIndexValid(index))
return;
AnimationState state = _states[index];
if (!state.enable)
state.SetEnable(true);
state.SetFade(targetWeight, fadeTime);
}
public void Stop(string stateName)
{
Stop(_GetStateIndex(stateName));
}
public void Stop(int index)
{
if (!IsStateIndexValid(index))
return;
AnimationState state = _states[index];
state.SetEnable(false);
state.SetWeight(0.0f);
state.ResetFade();
}
public void SetTime(float time)
{
for (int i = 0; i < _states.Length; i++)
_states[i]?.SetStateTime(time);
}
public void Rewind()
{
for (int i = 0; i < _states.Length; i++)
_states[i]?.SetStateTime(0.0f);
}
public void Rewind(string stateName)
{
Rewind(_GetStateIndex(stateName));
}
public void Rewind(int stateIndex)
{
if (IsStateIndexValid(stateIndex))
return;
_states[stateIndex].SetStateTime(0.0f);
}
}