Skip to content

Commit 110b454

Browse files
committed
Added tests for animator playback
1 parent 9268dc5 commit 110b454

20 files changed

+730
-3
lines changed

Assets/AdncAnimatorVariableStates/Editor/Testing.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AdncAnimatorVariableStates/Editor/Testing/AnimatorPlayback.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using Adnc.AnimatorVariables.Conditions;
2+
using Adnc.AnimatorVariables.Variables;
3+
using Adnc.Utility.Testing;
4+
using NUnit.Framework;
5+
using UnityEngine;
6+
using Object = UnityEngine.Object;
7+
8+
namespace Adnc.AnimatorVariables.Editors.Testing {
9+
public class TestAnimatorPlayback : TestBase {
10+
private const string ANIMATOR_STUB_LOC = "AnimatorTesting/AnimatorStub";
11+
12+
private AnimatorPlayback _playback;
13+
private Animator _anim;
14+
15+
[SetUp]
16+
public void SetupAnimatorPlayback () {
17+
_playback = ScriptableObject.CreateInstance<AnimatorPlayback>();
18+
var stub = Resources.Load<GameObject>(ANIMATOR_STUB_LOC);
19+
_anim = Object.Instantiate(stub).GetComponent<Animator>();
20+
}
21+
22+
[TearDown]
23+
public void TeardownAnimatorPlayback () {
24+
Object.DestroyImmediate(_anim.gameObject);
25+
_playback = null;
26+
_anim = null;
27+
}
28+
29+
[Test]
30+
public void StubBoolIsFalse () {
31+
Assert.IsFalse(_anim.GetBool("bool"));
32+
}
33+
34+
[Test]
35+
public void StubFloatIsZero () {
36+
Assert.IsTrue(Mathf.Abs(_anim.GetFloat("float")) < 0.1f);
37+
}
38+
39+
[Test]
40+
public void StubIntIsZero () {
41+
Assert.IsTrue(_anim.GetInteger("int") == 0);
42+
}
43+
44+
[Test]
45+
public void PlaySetsAnimatorBool () {
46+
_playback.bools.Add(new VarBool {
47+
name = "bool",
48+
value = true
49+
});
50+
51+
_playback.Play(_anim);
52+
53+
Assert.IsTrue(_anim.GetBool("bool"));
54+
}
55+
56+
[Test]
57+
public void PlaySetsAnimatorFloat () {
58+
_playback.floats.Add(new VarFloat {
59+
name = "float",
60+
value = 1
61+
});
62+
63+
_playback.Play(_anim);
64+
65+
Assert.AreEqual(_anim.GetFloat("float"), 1);
66+
}
67+
68+
[Test]
69+
public void PlaySetsAnimatorInt () {
70+
_playback.ints.Add(new VarInt {
71+
name = "int",
72+
value = 1
73+
});
74+
75+
_playback.Play(_anim);
76+
77+
Assert.AreEqual(_anim.GetInteger("int"), 1);
78+
}
79+
80+
[Test]
81+
public void IsConditionMetTrueWithNoAnimatorNull () {
82+
Assert.IsTrue(_playback.IsConditionsMet(null));
83+
}
84+
85+
[Test]
86+
public void IsConditionMetIsTrueWithNoConditions () {
87+
Assert.IsTrue(_playback.IsConditionsMet(_anim));
88+
}
89+
90+
[Test]
91+
public void IsConditionMetFalseWhenConditionsNotMet () {
92+
_playback.conditions.Add(new Condition {
93+
compareValues = OperatorAll.AreEqual,
94+
variableBool = new VarBool {
95+
name = "bool",
96+
value = true
97+
},
98+
variableType = ConditionVarType.Bool
99+
});
100+
101+
Assert.IsFalse(_playback.IsConditionsMet(_anim));
102+
}
103+
104+
[Test]
105+
public void IsConditionMetTrueWhenConditionsAreMet () {
106+
_playback.conditions.Add(new Condition {
107+
compareValues = OperatorAll.AreEqual,
108+
variableBool = new VarBool {
109+
name = "bool",
110+
value = true
111+
},
112+
variableType = ConditionVarType.Bool
113+
});
114+
115+
_anim.SetBool("bool", true);
116+
117+
Assert.IsTrue(_playback.IsConditionsMet(_anim));
118+
}
119+
}
120+
}

Assets/AdncAnimatorVariableStates/Editor/Testing/AnimatorPlayback/TestAnimatorPlayback.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AdncAnimatorVariableStates/Examples/Default/Default.unity

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,97 @@ NavMeshSettings:
112112
debug:
113113
m_Flags: 0
114114
m_NavMeshData: {fileID: 0}
115+
--- !u!1001 &548090549
116+
Prefab:
117+
m_ObjectHideFlags: 0
118+
serializedVersion: 2
119+
m_Modification:
120+
m_TransformParent: {fileID: 0}
121+
m_Modifications:
122+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
123+
propertyPath: m_LocalPosition.x
124+
value: 0
125+
objectReference: {fileID: 0}
126+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
127+
propertyPath: m_LocalPosition.y
128+
value: 0
129+
objectReference: {fileID: 0}
130+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
131+
propertyPath: m_LocalPosition.z
132+
value: 0
133+
objectReference: {fileID: 0}
134+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
135+
propertyPath: m_LocalRotation.x
136+
value: 0
137+
objectReference: {fileID: 0}
138+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
139+
propertyPath: m_LocalRotation.y
140+
value: 0
141+
objectReference: {fileID: 0}
142+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
143+
propertyPath: m_LocalRotation.z
144+
value: 0
145+
objectReference: {fileID: 0}
146+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
147+
propertyPath: m_LocalRotation.w
148+
value: 1
149+
objectReference: {fileID: 0}
150+
- target: {fileID: 4762678250890468, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
151+
propertyPath: m_RootOrder
152+
value: 1
153+
objectReference: {fileID: 0}
154+
m_RemovedComponents: []
155+
m_ParentPrefab: {fileID: 100100000, guid: 337ea3a1e781e4f70b1ba482c6954342, type: 2}
156+
m_IsPrefabParent: 0
157+
--- !u!1 &1279176631 stripped
158+
GameObject:
159+
m_PrefabParentObject: {fileID: 1850387426777382, guid: 337ea3a1e781e4f70b1ba482c6954342,
160+
type: 2}
161+
m_PrefabInternal: {fileID: 548090549}
162+
--- !u!212 &1279176634
163+
SpriteRenderer:
164+
m_ObjectHideFlags: 0
165+
m_PrefabParentObject: {fileID: 0}
166+
m_PrefabInternal: {fileID: 0}
167+
m_GameObject: {fileID: 1279176631}
168+
m_Enabled: 1
169+
m_CastShadows: 0
170+
m_ReceiveShadows: 0
171+
m_DynamicOccludee: 1
172+
m_MotionVectors: 1
173+
m_LightProbeUsage: 1
174+
m_ReflectionProbeUsage: 1
175+
m_Materials:
176+
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
177+
m_StaticBatchInfo:
178+
firstSubMesh: 0
179+
subMeshCount: 0
180+
m_StaticBatchRoot: {fileID: 0}
181+
m_ProbeAnchor: {fileID: 0}
182+
m_LightProbeVolumeOverride: {fileID: 0}
183+
m_ScaleInLightmap: 1
184+
m_PreserveUVs: 0
185+
m_IgnoreNormalsForChartDetection: 0
186+
m_ImportantGI: 0
187+
m_StitchLightmapSeams: 0
188+
m_SelectedEditorRenderState: 0
189+
m_MinimumChartSize: 4
190+
m_AutoUVMaxDistance: 0.5
191+
m_AutoUVMaxAngle: 89
192+
m_LightmapParameters: {fileID: 0}
193+
m_SortingLayerID: 0
194+
m_SortingLayer: 0
195+
m_SortingOrder: 0
196+
m_Sprite: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0}
197+
m_Color: {r: 1, g: 1, b: 1, a: 1}
198+
m_FlipX: 0
199+
m_FlipY: 0
200+
m_DrawMode: 0
201+
m_Size: {x: 0.16, y: 0.16}
202+
m_AdaptiveModeThreshold: 0.5
203+
m_SpriteTileMode: 0
204+
m_WasSpriteAssigned: 1
205+
m_MaskInteraction: 0
115206
--- !u!1 &1536667014
116207
GameObject:
117208
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)