1
1
using Adnc . AnimatorHelpers . Conditions ;
2
2
using Adnc . AnimatorHelpers . Variables ;
3
3
using Adnc . Utility . Testing ;
4
+ using AdncAnimatorHelpers . Editor . Testing . Utilities ;
4
5
using NUnit . Framework ;
5
6
using UnityEngine ;
6
7
using Object = UnityEngine . Object ;
@@ -10,35 +11,41 @@ public class TestAnimatorPlayback : TestBase {
10
11
private const string ANIMATOR_STUB_LOC = "AnimatorTesting/AnimatorStub" ;
11
12
12
13
private AnimatorPlayback _playback ;
13
- private Animator _anim ;
14
+ private AnimatorStub _stub ;
14
15
15
16
[ SetUp ]
16
17
public void SetupAnimatorPlayback ( ) {
17
18
_playback = ScriptableObject . CreateInstance < AnimatorPlayback > ( ) ;
18
- var stub = Resources . Load < GameObject > ( ANIMATOR_STUB_LOC ) ;
19
- _anim = Object . Instantiate ( stub ) . GetComponent < Animator > ( ) ;
19
+
20
+ _stub = new AnimatorStub ( new GameObject ( "AnimatorStub" ) ) ;
21
+ _stub . AnimatorCtrl . AddParameter ( "bool" , AnimatorControllerParameterType . Bool ) ;
22
+ _stub . AnimatorCtrl . AddParameter ( "float" , AnimatorControllerParameterType . Float ) ;
23
+ _stub . AnimatorCtrl . AddParameter ( "int" , AnimatorControllerParameterType . Int ) ;
24
+ _stub . AnimatorCtrl . AddParameter ( "trigger" , AnimatorControllerParameterType . Trigger ) ;
25
+
26
+ _stub . InjectCtrl ( ) ;
20
27
}
21
28
22
29
[ TearDown ]
23
30
public void TeardownAnimatorPlayback ( ) {
24
- Object . DestroyImmediate ( _anim . gameObject ) ;
31
+ Object . DestroyImmediate ( _stub . Animator . gameObject ) ;
25
32
_playback = null ;
26
- _anim = null ;
33
+ _stub = null ;
27
34
}
28
35
29
36
[ Test ]
30
37
public void StubBoolIsFalse ( ) {
31
- Assert . IsFalse ( _anim . GetBool ( "bool" ) ) ;
38
+ Assert . IsFalse ( _stub . Animator . GetBool ( "bool" ) ) ;
32
39
}
33
40
34
41
[ Test ]
35
42
public void StubFloatIsZero ( ) {
36
- Assert . IsTrue ( Mathf . Abs ( _anim . GetFloat ( "float" ) ) < 0.1f ) ;
43
+ Assert . IsTrue ( Mathf . Abs ( _stub . Animator . GetFloat ( "float" ) ) < 0.1f ) ;
37
44
}
38
45
39
46
[ Test ]
40
47
public void StubIntIsZero ( ) {
41
- Assert . IsTrue ( _anim . GetInteger ( "int" ) == 0 ) ;
48
+ Assert . IsTrue ( _stub . Animator . GetInteger ( "int" ) == 0 ) ;
42
49
}
43
50
44
51
[ Test ]
@@ -48,9 +55,9 @@ public void PlaySetsAnimatorBool () {
48
55
value = true
49
56
} ) ;
50
57
51
- _playback . Play ( _anim ) ;
58
+ _playback . Play ( _stub . Animator ) ;
52
59
53
- Assert . IsTrue ( _anim . GetBool ( "bool" ) ) ;
60
+ Assert . IsTrue ( _stub . Animator . GetBool ( "bool" ) ) ;
54
61
}
55
62
56
63
[ Test ]
@@ -60,9 +67,9 @@ public void PlaySetsAnimatorFloat () {
60
67
value = 1
61
68
} ) ;
62
69
63
- _playback . Play ( _anim ) ;
70
+ _playback . Play ( _stub . Animator ) ;
64
71
65
- Assert . AreEqual ( _anim . GetFloat ( "float" ) , 1 ) ;
72
+ Assert . AreEqual ( _stub . Animator . GetFloat ( "float" ) , 1 ) ;
66
73
}
67
74
68
75
[ Test ]
@@ -72,9 +79,9 @@ public void PlaySetsAnimatorInt () {
72
79
value = 1
73
80
} ) ;
74
81
75
- _playback . Play ( _anim ) ;
82
+ _playback . Play ( _stub . Animator ) ;
76
83
77
- Assert . AreEqual ( _anim . GetInteger ( "int" ) , 1 ) ;
84
+ Assert . AreEqual ( _stub . Animator . GetInteger ( "int" ) , 1 ) ;
78
85
}
79
86
80
87
[ Test ]
@@ -85,7 +92,7 @@ public void IsConditionMetTrueWithNoAnimatorNull () {
85
92
[ Test ]
86
93
public void IsConditionMetIsTrueWithNoConditions ( ) {
87
94
_playback . conditions . RemoveAt ( 0 ) ;
88
- Assert . IsTrue ( _playback . IsConditionsMet ( _anim ) ) ;
95
+ Assert . IsTrue ( _playback . IsConditionsMet ( _stub . Animator ) ) ;
89
96
}
90
97
91
98
[ Test ]
@@ -100,7 +107,7 @@ public void IsConditionMetFalseWhenConditionsNotMet () {
100
107
variableType = ConditionVarType . Bool
101
108
} ) ;
102
109
103
- Assert . IsFalse ( _playback . IsConditionsMet ( _anim ) ) ;
110
+ Assert . IsFalse ( _playback . IsConditionsMet ( _stub . Animator ) ) ;
104
111
}
105
112
106
113
[ Test ]
@@ -115,9 +122,11 @@ public void IsConditionMetTrueWhenConditionsAreMet () {
115
122
variableType = ConditionVarType . Bool
116
123
} ) ;
117
124
118
- _anim . SetBool ( "bool" , true ) ;
125
+ _stub . Animator . SetBool ( "bool" , true ) ;
119
126
120
- Assert . IsTrue ( _playback . IsConditionsMet ( _anim ) ) ;
127
+ Assert . IsTrue ( _playback . IsConditionsMet ( _stub . Animator ) ) ;
121
128
}
129
+
130
+
122
131
}
123
132
}
0 commit comments