Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMCL-0000: Add a simple test to ensure spline cart is working correctly #1002

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs
Original file line number Diff line number Diff line change
@@ -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<SplineContainer>();
m_SplineContainer.Spline = SplineFactory.CreateLinear(
new List<float3> { 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<CinemachineSplineCart>();
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);
}
}
}
11 changes: 11 additions & 0 deletions com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading