diff --git a/com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs b/com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs new file mode 100644 index 000000000..02d02870b --- /dev/null +++ b/com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using UnityEngine; +using UnityEngine.TestTools; +using UnityEngine.Splines; +using Unity.Mathematics; + +namespace Unity.Cinemachine.Tests +{ + [TestFixture] + public class CinemachineSplineCartTest : CinemachineRuntimeFixtureBase + { + CinemachineSplineCart m_CmSplineCart; + SplineContainer m_SplineContainer; + + [SetUp] + public void Setup() + { + base.SetUp(); + + m_SplineContainer = CreateGameObject("Dolly Track", typeof(SplineContainer)).GetComponent(); + m_SplineContainer.Spline = SplineFactory.CreateLinear( + new List { new(7, 1, -6), new(13, 1, -6), new(13, 1, 1), new(7, 1, 1) }, true); + m_CmSplineCart = CreateGameObject("CM cart", typeof(CinemachineSplineCart)).GetComponent(); + m_CmSplineCart.Spline = m_SplineContainer; + } + + [TearDown] + public override void TearDown() + { + base.TearDown(); + } + + [UnityTest] + public IEnumerator CartPositionIsCorrect() + { + m_CmSplineCart.PositionUnits = PathIndexUnit.Distance; + m_CmSplineCart.SplinePosition = 0; + yield return null; + UnityEngine.Assertions.Assert.AreApproximatelyEqual( + Vector3.Distance(m_CmSplineCart.transform.position, new Vector3(7, 1, -6)), 0, 0.1f); + + m_CmSplineCart.PositionUnits = PathIndexUnit.Normalized; + m_CmSplineCart.SplinePosition = 1; + yield return null; + UnityEngine.Assertions.Assert.AreApproximatelyEqual( + Vector3.Distance(m_CmSplineCart.transform.position, new Vector3(7, 1, -6)), 0, 0.1f); + } + } +} diff --git a/com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs.meta b/com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs.meta new file mode 100644 index 000000000..330c6579c --- /dev/null +++ b/com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 80bda8217ab134de59e131bae497bf90 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: