Tanoda
InteractionEngineTestBase.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9#if LEAP_TESTS
10
11using Leap.Unity.Query;
12using NUnit.Framework;
13using System.Collections.Generic;
14using UnityEngine;
15using UnityEngine.Playables;
16
18
19 public abstract class InteractionEngineTestBase : LeapTestBase {
20
21 protected const int WAIT_FOR_INTERACTION_FRAME_LIMIT = 500;
22
23 #region Test Object Names
24
28 protected const string DEFAULT_RIG = "IE Test Default Rig";
29
33 protected const string DEFAULT_STAGE = "IE Test Default Stage";
34
40 protected const string GRASP_THROW_RIG = "IE Test Playback Rig - Grasp and Throw";
41
47 protected const string PRESS_BUTTON_RIG = "IE Test Playback Rig - Press Button";
48
49 #endregion
50
51 #region Test Rig Objects
52
53 protected GameObject rigObj;
54
58 protected PlayableDirector recording;
59
63 protected LeapProvider provider;
64
68 protected InteractionManager manager;
69
70 protected InteractionHand leftHand;
71 protected InteractionHand rightHand;
72 protected InteractionXRController leftVRController;
73 protected InteractionXRController rightVRController;
74
75 #endregion
76
77 #region Test Stage Objects
78
79 protected GameObject stageObj;
80
84 protected InteractionBehaviour box0;
85
89 protected InteractionBehaviour box1;
90
94 protected InteractionBehaviour box2;
95
99 protected InteractionButton button;
100
101 #endregion
102
108 protected void InitTest(string rigObjName, string stageObjName) {
109
110 // Load test rig objects.
111 base.InitTest(rigObjName);
112 rigObj = testObj;
113 recording = rigObj.GetComponentInChildren<PlayableDirector>();
114 provider = rigObj.GetComponentInChildren<LeapProvider>();
115 manager = rigObj.GetComponentInChildren<InteractionManager>();
116
117 foreach (var controller in manager.interactionControllers) {
118 if (controller.intHand != null && controller.isLeft) {
119 leftHand = controller.intHand;
120 continue;
121 }
122 if (controller.intHand != null && !controller.isLeft) {
123 rightHand = controller.intHand;
124 continue;
125 }
126
127 var vrController = controller as InteractionXRController;
128 if (vrController != null && vrController.isLeft) {
129 leftVRController = vrController;
130 continue;
131 }
132 if (vrController != null && !vrController.isLeft) {
133 rightVRController = vrController;
134 continue;
135 }
136 }
137
138 // Load stage objects.
139 stageObj = LoadObject(stageObjName);
140
141 var intObjs = Pool<List<InteractionBehaviour>>.Spawn();
142 try {
143 stageObj.GetComponentsInChildren<InteractionBehaviour>(true, intObjs);
144
145 // Load "simple box" interaction objects.
146 foreach (var simpleBoxObj in intObjs
147 .Query()
148 .Where(o => o.primaryHoverColliders.Count == 1
149 && o.primaryHoverColliders[0] is BoxCollider
150 && !o.ignoreContact
151 && !o.ignoreGrasping)) {
152 if (box0 == null) { box0 = simpleBoxObj; continue; }
153 if (box1 == null) { box1 = simpleBoxObj; continue; }
154 if (box2 == null) { box2 = simpleBoxObj; continue; }
155 }
156
157 foreach (var interactionButtonObj in intObjs.Query()
158 .Where(o => o is InteractionButton)) {
159 if (button == null) button = interactionButtonObj as InteractionButton;
160 }
161 }
162 finally {
163 intObjs.Clear();
164 Pool<List<InteractionBehaviour>>.Recycle(intObjs);
165 }
166 }
167
171 protected override void InitTest(string stageObjName) {
172 InitTest(DEFAULT_RIG, stageObjName);
173 }
174
178 protected void InitTest() {
179 InitTest(DEFAULT_RIG, DEFAULT_STAGE);
180 }
181
182 [TearDown]
183 protected virtual void Teardown() {
184 UnityEngine.Object.DestroyImmediate(rigObj);
185 UnityEngine.Object.DestroyImmediate(stageObj);
186
187 Debug.ClearDeveloperConsole();
188 }
189
190 }
191
192}
193
194#endif // LEAP_TESTS
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19