11using Adnc . AnimatorHelpers . Conditions ;
22using Adnc . AnimatorHelpers . Variables ;
33using Adnc . Utility . Testing ;
4+ using AdncAnimatorHelpers . Editor . Testing . Utilities ;
45using NUnit . Framework ;
56using UnityEngine ;
67using Object = UnityEngine . Object ;
@@ -10,35 +11,41 @@ public class TestAnimatorPlayback : TestBase {
1011 private const string ANIMATOR_STUB_LOC = "AnimatorTesting/AnimatorStub" ;
1112
1213 private AnimatorPlayback _playback ;
13- private Animator _anim ;
14+ private AnimatorStub _stub ;
1415
1516 [ SetUp ]
1617 public void SetupAnimatorPlayback ( ) {
1718 _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 ( ) ;
2027 }
2128
2229 [ TearDown ]
2330 public void TeardownAnimatorPlayback ( ) {
24- Object . DestroyImmediate ( _anim . gameObject ) ;
31+ Object . DestroyImmediate ( _stub . Animator . gameObject ) ;
2532 _playback = null ;
26- _anim = null ;
33+ _stub = null ;
2734 }
2835
2936 [ Test ]
3037 public void StubBoolIsFalse ( ) {
31- Assert . IsFalse ( _anim . GetBool ( "bool" ) ) ;
38+ Assert . IsFalse ( _stub . Animator . GetBool ( "bool" ) ) ;
3239 }
3340
3441 [ Test ]
3542 public void StubFloatIsZero ( ) {
36- Assert . IsTrue ( Mathf . Abs ( _anim . GetFloat ( "float" ) ) < 0.1f ) ;
43+ Assert . IsTrue ( Mathf . Abs ( _stub . Animator . GetFloat ( "float" ) ) < 0.1f ) ;
3744 }
3845
3946 [ Test ]
4047 public void StubIntIsZero ( ) {
41- Assert . IsTrue ( _anim . GetInteger ( "int" ) == 0 ) ;
48+ Assert . IsTrue ( _stub . Animator . GetInteger ( "int" ) == 0 ) ;
4249 }
4350
4451 [ Test ]
@@ -48,9 +55,9 @@ public void PlaySetsAnimatorBool () {
4855 value = true
4956 } ) ;
5057
51- _playback . Play ( _anim ) ;
58+ _playback . Play ( _stub . Animator ) ;
5259
53- Assert . IsTrue ( _anim . GetBool ( "bool" ) ) ;
60+ Assert . IsTrue ( _stub . Animator . GetBool ( "bool" ) ) ;
5461 }
5562
5663 [ Test ]
@@ -60,9 +67,9 @@ public void PlaySetsAnimatorFloat () {
6067 value = 1
6168 } ) ;
6269
63- _playback . Play ( _anim ) ;
70+ _playback . Play ( _stub . Animator ) ;
6471
65- Assert . AreEqual ( _anim . GetFloat ( "float" ) , 1 ) ;
72+ Assert . AreEqual ( _stub . Animator . GetFloat ( "float" ) , 1 ) ;
6673 }
6774
6875 [ Test ]
@@ -72,9 +79,9 @@ public void PlaySetsAnimatorInt () {
7279 value = 1
7380 } ) ;
7481
75- _playback . Play ( _anim ) ;
82+ _playback . Play ( _stub . Animator ) ;
7683
77- Assert . AreEqual ( _anim . GetInteger ( "int" ) , 1 ) ;
84+ Assert . AreEqual ( _stub . Animator . GetInteger ( "int" ) , 1 ) ;
7885 }
7986
8087 [ Test ]
@@ -85,7 +92,7 @@ public void IsConditionMetTrueWithNoAnimatorNull () {
8592 [ Test ]
8693 public void IsConditionMetIsTrueWithNoConditions ( ) {
8794 _playback . conditions . RemoveAt ( 0 ) ;
88- Assert . IsTrue ( _playback . IsConditionsMet ( _anim ) ) ;
95+ Assert . IsTrue ( _playback . IsConditionsMet ( _stub . Animator ) ) ;
8996 }
9097
9198 [ Test ]
@@ -100,7 +107,7 @@ public void IsConditionMetFalseWhenConditionsNotMet () {
100107 variableType = ConditionVarType . Bool
101108 } ) ;
102109
103- Assert . IsFalse ( _playback . IsConditionsMet ( _anim ) ) ;
110+ Assert . IsFalse ( _playback . IsConditionsMet ( _stub . Animator ) ) ;
104111 }
105112
106113 [ Test ]
@@ -115,9 +122,11 @@ public void IsConditionMetTrueWhenConditionsAreMet () {
115122 variableType = ConditionVarType . Bool
116123 } ) ;
117124
118- _anim . SetBool ( "bool" , true ) ;
125+ _stub . Animator . SetBool ( "bool" , true ) ;
119126
120- Assert . IsTrue ( _playback . IsConditionsMet ( _anim ) ) ;
127+ Assert . IsTrue ( _playback . IsConditionsMet ( _stub . Animator ) ) ;
121128 }
129+
130+
122131 }
123132}
0 commit comments