2022-05-08 12:09:30 +01:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.TestTools;
|
|
|
|
|
2022-05-08 12:17:57 +01:00
|
|
|
namespace X10D.Unity.Tests
|
2022-05-08 12:09:30 +01:00
|
|
|
{
|
|
|
|
public class TransformTests
|
|
|
|
{
|
|
|
|
[UnityTest]
|
|
|
|
public IEnumerator LookAt_ShouldRotateSameAsTransform()
|
|
|
|
{
|
|
|
|
var first = new GameObject {transform = {position = Vector3.zero, rotation = Quaternion.identity}};
|
|
|
|
var second = new GameObject {transform = {position = Vector3.right, rotation = Quaternion.identity}};
|
|
|
|
Transform firstTransform = first.transform;
|
|
|
|
Transform secondTransform = second.transform;
|
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(firstTransform.rotation, Is.EqualTo(Quaternion.identity));
|
|
|
|
Assert.That(secondTransform.rotation, Is.EqualTo(Quaternion.identity));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
firstTransform.LookAt(secondTransform);
|
|
|
|
Quaternion expected = firstTransform.rotation;
|
|
|
|
|
|
|
|
firstTransform.rotation = Quaternion.identity;
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(firstTransform.rotation, Is.EqualTo(Quaternion.identity));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
firstTransform.LookAt(second);
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(firstTransform.rotation, Is.EqualTo(expected));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
firstTransform.rotation = Quaternion.identity;
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(firstTransform.rotation, Is.EqualTo(Quaternion.identity));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[UnityTest]
|
|
|
|
public IEnumerator SetParent_ShouldSetParent()
|
|
|
|
{
|
|
|
|
var first = new GameObject {transform = {position = Vector3.zero, rotation = Quaternion.identity}};
|
|
|
|
var second = new GameObject {transform = {position = Vector3.right, rotation = Quaternion.identity}};
|
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(first.transform.parent, Is.EqualTo(null));
|
|
|
|
Assert.That(second.transform.parent, Is.EqualTo(null));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
first.transform.SetParent(second);
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(first.transform.parent, Is.EqualTo(second.transform));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
first.transform.SetParent(null!);
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(first.transform.parent, Is.EqualTo(null));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
second.transform.SetParent(first);
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(second.transform.parent, Is.EqualTo(first.transform));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|