|
1 | 1 | using UnityEngine;
|
2 | 2 | using UnityEditor;
|
3 | 3 | using NUnit.Framework;
|
| 4 | +using System.Collections; |
4 | 5 | using System.Collections.Generic;
|
5 | 6 | using UnityEngine.Animations;
|
6 | 7 |
|
7 | 8 | namespace FbxExporters.UnitTests
|
8 | 9 | {
|
| 10 | + public class ConstraintAnimationTestDataClass |
| 11 | + { |
| 12 | + public static IEnumerable TestCases |
| 13 | + { |
| 14 | + get |
| 15 | + { |
| 16 | + yield return new TestCaseData(new float[] { 1f, 20f, 30f }, new float[] { 0f, 0.5f, 1f }, "m_Weight").Returns(1); |
| 17 | + yield return new TestCaseData(new float[] { 2, 9, 33 }, new float[] { 0.1f, 0.67f, 0.2f }, "m_Sources.Array.data[0].weight").Returns(1); |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | + |
9 | 22 | public class FbxConstraintTest : ExporterTestBase
|
10 | 23 | {
|
11 | 24 | /// <summary>
|
@@ -174,6 +187,35 @@ public void TestAimConstraintExport()
|
174 | 187 | Assert.That(expConstraint.worldUpVector, Is.EqualTo(aimConstraint.worldUpVector));
|
175 | 188 | }
|
176 | 189 |
|
| 190 | + [Test, TestCaseSource(typeof(ConstraintAnimationTestDataClass), "TestCases")] |
| 191 | + public int TestWeightAnimation(float[] keyTimes, float[] keyValues, string propertyName) |
| 192 | + { |
| 193 | + var go = new GameObject("root"); |
| 194 | + var source = new GameObject("source"); |
| 195 | + |
| 196 | + source.transform.parent = go.transform; |
| 197 | + |
| 198 | + var constraint = go.AddComponent<RotationConstraint>(); |
| 199 | + Assert.That(constraint, Is.Not.Null); |
| 200 | + |
| 201 | + var cSource = new ConstraintSource(); |
| 202 | + cSource.sourceTransform = source.transform; |
| 203 | + |
| 204 | + int index = constraint.AddSource(cSource); |
| 205 | + Assert.That(index, Is.EqualTo(0)); |
| 206 | + |
| 207 | + var keyData = new FbxAnimationTest.PropertyKeyData |
| 208 | + { |
| 209 | + targetObject = go, |
| 210 | + componentType = typeof(RotationConstraint), |
| 211 | + propertyName = propertyName, |
| 212 | + keyTimes = keyTimes, |
| 213 | + keyFloatValues = keyValues |
| 214 | + }; |
| 215 | + var tester = new FbxAnimationTest.AnimTester { keyData = keyData, testName = "ConstraintWeightAnim_" + propertyName, path = GetRandomFbxFilePath() }; |
| 216 | + |
| 217 | + return tester.DoIt(); |
| 218 | + } |
177 | 219 |
|
178 | 220 | public bool AreEqual(Vector3 a, Vector3 b, double epsilon = 0.0001)
|
179 | 221 | {
|
|
0 commit comments