2022-01-12 12:29:36 +01:00

349 lines
10 KiB
C#

/*
#if UNITY_EDITOR
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
namespace Passer.Pawn {
public class GrabbingTest {
//static GrabbingTest() {
// EditorSceneManager.sceneOpened += SceneOpened;
//}
//private static void SceneOpened(Scene scene, OpenSceneMode mode) {
// if ((scene.name == "ObjectTable Pawn" ||
// scene.name == "ObjectTable Pawn VR" ||
// scene.name == "ObjectTable Humanoid") &&
// EditorSceneManager.loadedSceneCount == 1) {
// Debug.Log("Additive opening ObjectTable scene");
// EditorSceneManager.OpenScene("Assets/PawnControl/Demo/Environments/ObjectTable.unity", OpenSceneMode.Additive);
// }
//}
public void Setup() {
UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("_TestCases/Grabbing/[Test]GrabbingPawn");
UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Passer/PawnControl/Demo/Environments/ObjectTable", LoadSceneMode.Additive);
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabStaticObject() {
Debug.Log("[GrabbingPawnTest] GrabStaticObject");
//System.Console.WriteLine("[GrabbingPawnTest] GrabStaticObject");
Setup();
Debug.Log("[GrabbingPawnTest] GrabStaticObject - loading scene");
yield return new WaitForSeconds(1);
Debug.Log("[GrabbingPawnTest] GrabStaticObject - loaded scene");
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
GameObject obj = GameObject.Find("StaticCube");
Assert.IsFalse(obj == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
Debug.Log("[GrabbingPawnTest] GrabStaticObject - start walking");
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
Debug.Log("[GrabbingPawnTest] GrabStaticObject - end walking, grabbing");
#region Grab
GameObject grabbedObject = Grab(pawn, obj);
Assert.IsTrue(grabbedObject == null);
#endregion Grab
Debug.Log("[GrabbingPawnTest] GrabStaticObject - grabbed, let go");
#region LetGo
grabbedObject = LetGo(pawn);
#endregion Let Go
Debug.Log("[GrabbingPawnTest] GrabStaticObject - let go complete");
yield return new WaitForSeconds(1);
System.Console.WriteLine("[GrabbingPawnTest] GrabStaticObject SUCCESS");
yield return null;
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabStaticObjectHandle() {
Setup();
yield return new WaitForSeconds(1);
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
GameObject obj = GameObject.Find("StaticCubeWithHandle");
Assert.IsFalse(obj == null);
Handle handle = obj.GetComponentInChildren<Handle>();
Assert.IsFalse(handle == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
#region Grab
GameObject grabbedObject = Grab(pawn, obj);
Assert.AreEqual(handle.gameObject, grabbedObject);
#endregion Grab
#region LetGo
grabbedObject = LetGo(pawn);
#endregion Let Go
yield return new WaitForSeconds(1);
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabHeavyObjectHandle() {
Setup();
yield return new WaitForSeconds(1);
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
GameObject obj = GameObject.Find("HeavyCube");
Assert.IsFalse(obj == null);
Handle handle = obj.GetComponentInChildren<Handle>();
Assert.IsFalse(handle == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
#region Grab
GameObject grabbedObject = Grab(pawn, obj);
Assert.AreEqual(obj, grabbedObject);
#endregion Grab
#region LetGo
grabbedObject = LetGo(pawn);
#endregion Let Go
yield return new WaitForSeconds(1);
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabRigidbody() {
Setup();
yield return new WaitForSeconds(1);
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
GameObject obj = GameObject.Find("CubeRigidbody");
Assert.IsFalse(obj == null);
Handle handle = obj.GetComponentInChildren<Handle>();
Assert.IsTrue(handle == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
#region Grab
GameObject grabbedObject = Grab(pawn, obj);
Assert.AreEqual(obj, grabbedObject);
#endregion Grab
#region LetGo
grabbedObject = LetGo(pawn);
#endregion Let Go
yield return new WaitForSeconds(1);
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabRigidbodyHandle() {
Setup();
yield return new WaitForSeconds(1);
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
PawnHand hand = pawn.rightHandTarget;
GameObject obj = GameObject.Find("CubeWithHandle");
Assert.IsFalse(obj == null);
Handle handle = obj.GetComponentInChildren<Handle>();
Assert.IsFalse(handle == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
#region Grab
hand.Grab(obj, false);
Assert.AreEqual(obj, hand.grabbedObject);
Assert.AreEqual(obj, hand.grabSocket.attachedTransform.gameObject);
Assert.AreEqual(handle, hand.grabbedHandle);
Assert.AreEqual(handle, hand.grabSocket.attachedHandle);
Assert.AreEqual(obj.transform.parent, hand.grabSocket.transform);
#endregion Grab
#region LetGo
hand.LetGo();
Assert.AreEqual(null, hand.grabbedObject);
Assert.AreEqual(null, hand.grabSocket.attachedTransform);
Assert.AreEqual(null, hand.grabbedHandle);
Assert.AreEqual(null, hand.grabSocket.attachedHandle);
#endregion Let Go
yield return new WaitForSeconds(1);
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabKinematicRigidbodyWithPhysics() {
Setup();
yield return new WaitForSeconds(1);
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
GameObject obj = GameObject.Find("KinematicCube");
Assert.IsFalse(obj == null);
Handle handle = obj.GetComponentInChildren<Handle>();
Assert.IsFalse(handle == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
#region Grab
GameObject grabbedObject = Grab(pawn, obj);
Assert.AreEqual(obj, grabbedObject);
#endregion Grab
#region LetGo
grabbedObject = LetGo(pawn);
#endregion Let Go
yield return new WaitForSeconds(1);
}
[UnityTest]
[Category("Grabbing")]
public IEnumerator GrabMechanicalJoint() {
Setup();
yield return new WaitForSeconds(1);
PawnControl pawn = Object.FindObjectOfType<PawnControl>();
Assert.IsFalse(pawn == null);
GameObject obj = GameObject.Find("MechanicalJointCube");
Assert.IsFalse(obj == null);
Handle handle = obj.GetComponentInChildren<Handle>();
Assert.IsFalse(handle == null);
SpawnPoint location = obj.transform.parent.GetComponentInChildren<SpawnPoint>();
Assert.IsFalse(location == null);
#region Walk
yield return pawn.WalkTo(location.transform.position, location.transform.rotation);
#endregion Walk
#region Grab
GameObject grabbedObject = Grab(pawn, obj);
Assert.AreEqual(obj, grabbedObject);
#endregion Grab
#region LetGo
grabbedObject = LetGo(pawn);
#endregion Let Go
yield return new WaitForSeconds(1);
}
#region Tools
protected GameObject Grab(PawnControl pawn, GameObject obj) {
pawn.rightHandTarget.Grab(obj, false);
return pawn.rightHandTarget.grabbedObject;
}
protected GameObject LetGo(PawnControl pawn) {
pawn.rightHandTarget.LetGo();
return pawn.rightHandTarget.grabbedObject;
}
#endregion Tools
}
}
#endif
*/