Firstborn/Library/PackageCache/com.unity.cinemachine@2.8.9/Tests/Runtime/CameraPositionTests.cs

109 lines
4.4 KiB
C#
Raw Normal View History

2023-03-28 13:24:16 -04:00
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Cinemachine;
using UnityEngine.TestTools.Utils;
namespace Tests.Runtime
{
public class CameraPositionTests : CinemachineFixtureBase
{
private CinemachineVirtualCamera vcam;
private GameObject followObject;
[SetUp]
public override void SetUp()
{
CreateGameObject("MainCamera", typeof(Camera), typeof(CinemachineBrain));
vcam = CreateGameObject("CM Vcam", typeof(CinemachineVirtualCamera)).GetComponent<CinemachineVirtualCamera>();
vcam.Priority = 100;
followObject = CreateGameObject("Follow Object");
base.SetUp();
}
[UnityTest]
public IEnumerator DoNothing()
{
vcam.Follow = followObject.transform;
Vector3 oldPos = vcam.transform.position;
followObject.transform.position += new Vector3(2, 2, 2);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(oldPos).Using(Vector3EqualityComparer.Instance));
}
[UnityTest]
public IEnumerator ThirdPerson()
{
vcam.AddCinemachineComponent<Cinemachine3rdPersonFollow>();
vcam.Follow = followObject.transform;
followObject.transform.position += new Vector3(10, 0, 0);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(followObject.transform.position).Using(Vector3EqualityComparer.Instance));
}
[UnityTest]
public IEnumerator FramingTransposer()
{
CinemachineFramingTransposer component = vcam.AddCinemachineComponent<CinemachineFramingTransposer>();
component.m_XDamping = 0;
component.m_YDamping = 0;
component.m_ZDamping = 0;
component.m_CameraDistance = 1f;
vcam.Follow = followObject.transform;
followObject.transform.position += new Vector3(10, 0, 0);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(new Vector3(10, 0, -component.m_CameraDistance)).Using(Vector3EqualityComparer.Instance));
}
[UnityTest]
public IEnumerator HardLockToTarget()
{
vcam.AddCinemachineComponent<CinemachineHardLockToTarget>();
vcam.Follow = followObject.transform;
followObject.transform.position += new Vector3(10, 0, 0);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(followObject.transform.position).Using(Vector3EqualityComparer.Instance));
}
[UnityTest]
public IEnumerator OrbTransposer()
{
CinemachineOrbitalTransposer component = vcam.AddCinemachineComponent<CinemachineOrbitalTransposer>();
component.m_XDamping = 0;
component.m_YDamping = 0;
component.m_ZDamping = 0;
component.m_FollowOffset = new Vector3(0, 0, 0);
vcam.Follow = followObject.transform;
followObject.transform.position += new Vector3(10, 0, 0);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(followObject.transform.position).Using(Vector3EqualityComparer.Instance));
}
[UnityTest]
public IEnumerator TrackedDolly()
{
vcam.AddCinemachineComponent<CinemachineTrackedDolly>();
vcam.Follow = followObject.transform;
Vector3 oldPos = vcam.transform.position;
followObject.transform.position += new Vector3(2, 2, 2);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(oldPos).Using(Vector3EqualityComparer.Instance));
}
[UnityTest]
public IEnumerator Transposer()
{
CinemachineTransposer component = vcam.AddCinemachineComponent<CinemachineTransposer>();
component.m_XDamping = 0;
component.m_YDamping = 0;
component.m_ZDamping = 0;
component.m_FollowOffset = new Vector3(0, 0, 0);
vcam.Follow = followObject.transform;
followObject.transform.position += new Vector3(10, 0, 0);
yield return null;
Assert.That(vcam.State.FinalPosition, Is.EqualTo(followObject.transform.position).Using(Vector3EqualityComparer.Instance));
}
}
}