Created
December 3, 2021 10:28
-
-
Save ikuko/49b8275946e9404cac4551b0ee7f36e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public abstract class InstantiateTestBase | |
{ | |
protected GameObject Parent; | |
protected GameObject Child; | |
[OneTimeSetUp] | |
public void OneTimeSetUp() | |
{ | |
Parent = new GameObject("Parent"); | |
Parent.transform.localPosition = new Vector3(1f, 1f, 1f); | |
Parent.transform.localRotation = Quaternion.Euler(10f, 20f, 30f); | |
Parent.transform.localScale = new Vector3(0.9f, 0.9f, 0.9f); | |
Child = new GameObject("Child"); | |
Child.transform.SetParent(Parent.transform); | |
Child.transform.localPosition = new Vector3(2f, 2f, 2f); | |
Child.transform.localRotation = Quaternion.Euler(10f, 20f, 30f); | |
Child.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); | |
} | |
[OneTimeTearDown] | |
public void OneTimeTearDown() | |
{ | |
} | |
} | |
public class UdonSharpLibInternalInstantiationShimInstantiateTest : InstantiateTestBase | |
{ | |
[Test()] | |
public void EqualsTransform_GameObject([Values(0, 1)] int _original) | |
{ | |
var original = _original == 0 ? Parent : Child; | |
var l = UnityEngine.GameObject.Instantiate(original); | |
var r = UdonSharp.Lib.Internal.InstantiationShim.Instantiate(original); | |
Assert.AreEqual(l.transform.position, r.transform.position); | |
Assert.AreEqual(l.transform.localPosition, r.transform.localPosition); | |
Assert.AreEqual(l.transform.rotation, r.transform.rotation); | |
Assert.AreEqual(l.transform.localRotation, r.transform.localRotation); | |
Assert.AreEqual(l.transform.localScale, r.transform.localScale); | |
} | |
[Test()] | |
public void EqualsTransform_GameObject_Vector3_Quaternion([Values(0, 1)] int _original, [Random(1)] float _position, [Random(1)] float _rotation) | |
{ | |
var original = _original == 0 ? Parent : Child; | |
var position = new Vector3(_position, _position, _position); | |
var rotation = Quaternion.Euler(_rotation, _rotation, _rotation); | |
var l = UnityEngine.GameObject.Instantiate(original, position, rotation); | |
var r = UdonSharp.Lib.Internal.InstantiationShim.Instantiate(original, position, rotation); | |
Assert.AreEqual(l.transform.position, r.transform.position); | |
Assert.AreEqual(l.transform.localPosition, r.transform.localPosition); | |
Assert.AreEqual(l.transform.rotation, r.transform.rotation); | |
Assert.AreEqual(l.transform.localRotation, r.transform.localRotation); | |
Assert.AreEqual(l.transform.localScale, r.transform.localScale); | |
} | |
[Test()] | |
public void EqualsTransform_GameObject_Transform([Values(0, 1)] int _original) | |
{ | |
var original = _original == 0 ? Parent : Child; | |
var l = UnityEngine.GameObject.Instantiate(original, Parent.transform); | |
var r = UdonSharp.Lib.Internal.InstantiationShim.Instantiate(original, Parent.transform); | |
Assert.AreEqual(l.transform.position, r.transform.position); | |
Assert.AreEqual(l.transform.localPosition, r.transform.localPosition); | |
Assert.AreEqual(l.transform.rotation, r.transform.rotation); | |
Assert.AreEqual(l.transform.localRotation, r.transform.localRotation); | |
Assert.AreEqual(l.transform.localScale, r.transform.localScale); | |
} | |
[Test()] | |
public void EqualsTransform_GameObject_Transform_Bool([Values(0, 1)] int _original, [Values] bool worldPositionStays) | |
{ | |
var original = _original == 0 ? Parent : Child; | |
var l = UnityEngine.GameObject.Instantiate(original, Parent.transform, worldPositionStays); | |
var r = UdonSharp.Lib.Internal.InstantiationShim.Instantiate(original, Parent.transform, worldPositionStays); | |
Assert.AreEqual(l.transform.position, r.transform.position); | |
Assert.AreEqual(l.transform.localPosition, r.transform.localPosition); | |
Assert.AreEqual(l.transform.rotation, r.transform.rotation); | |
Assert.AreEqual(l.transform.localRotation, r.transform.localRotation); | |
Assert.AreEqual(l.transform.localScale, r.transform.localScale); | |
//Assert.That(Mathf.Approximately(l.transform.localScale.x, r.transform.localScale.x)); | |
//Assert.That(Mathf.Approximately(l.transform.localScale.y, r.transform.localScale.y)); | |
//Assert.That(Mathf.Approximately(l.transform.localScale.z, r.transform.localScale.z)); | |
} | |
[Test()] | |
public void EqualsTransform_GameObject_Vector3_Quaternion_Transform([Values(0, 1)] int _original, [Random(1)] float _position, [Random(1)] float _rotation) | |
{ | |
var original = _original == 0 ? Parent : Child; | |
var position = new Vector3(_position, _position, _position); | |
var rotation = Quaternion.Euler(_rotation, _rotation, _rotation); | |
var l = UnityEngine.GameObject.Instantiate(original, position, rotation, Parent.transform); | |
var r = UdonSharp.Lib.Internal.InstantiationShim.Instantiate(original, position, rotation, Parent.transform); | |
Assert.AreEqual(l.transform.position, r.transform.position); | |
Assert.AreEqual(l.transform.localPosition, r.transform.localPosition); | |
Assert.AreEqual(l.transform.rotation, r.transform.rotation); | |
Assert.AreEqual(l.transform.localRotation, r.transform.localRotation); | |
Assert.AreEqual(l.transform.localScale, r.transform.localScale); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment