@@ -27,6 +27,16 @@ public class RayPerception3DTests
27
27
const string k_CubeTag = "Player" ;
28
28
const string k_SphereTag = "Respawn" ;
29
29
30
+ [ TearDown ]
31
+ public void RemoveGameObjects ( )
32
+ {
33
+ var objects = GameObject . FindObjectsOfType < GameObject > ( ) ;
34
+ foreach ( var o in objects )
35
+ {
36
+ UnityEngine . Object . DestroyImmediate ( o ) ;
37
+ }
38
+ }
39
+
30
40
void SetupScene ( )
31
41
{
32
42
/* Creates game objects in the world for testing.
@@ -44,18 +54,22 @@ void SetupScene()
44
54
var cube = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
45
55
cube . transform . position = new Vector3 ( 0 , 0 , 10 ) ;
46
56
cube . tag = k_CubeTag ;
57
+ cube . name = "cube" ;
47
58
48
59
var sphere1 = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
49
60
sphere1 . transform . position = new Vector3 ( - 5 , 0 , 5 ) ;
50
61
sphere1 . tag = k_SphereTag ;
62
+ sphere1 . name = "sphere1" ;
51
63
52
64
var sphere2 = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
53
65
sphere2 . transform . position = new Vector3 ( 5 , 0 , 5 ) ;
54
66
// No tag for sphere2
67
+ sphere2 . name = "sphere2" ;
55
68
56
69
var sphere3 = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
57
70
sphere3 . transform . position = new Vector3 ( 0 , 0 , - 10 ) ;
58
71
sphere3 . tag = k_SphereTag ;
72
+ sphere3 . name = "sphere3" ;
59
73
60
74
Physics . SyncTransforms ( ) ;
61
75
}
@@ -296,5 +310,33 @@ public void TestRayZeroLength()
296
310
Assert . LessOrEqual ( outputBuffer [ 2 ] , 1.0f ) ;
297
311
}
298
312
}
313
+
314
+ [ Test ]
315
+ public void TestStaticPerceive ( )
316
+ {
317
+ SetupScene ( ) ;
318
+ var obj = new GameObject ( "agent" ) ;
319
+ var perception = obj . AddComponent < RayPerceptionSensorComponent3D > ( ) ;
320
+
321
+ perception . RaysPerDirection = 0 ; // single ray
322
+ perception . MaxRayDegrees = 45 ;
323
+ perception . RayLength = 20 ;
324
+ perception . DetectableTags = new List < string > ( ) ;
325
+ perception . DetectableTags . Add ( k_CubeTag ) ;
326
+ perception . DetectableTags . Add ( k_SphereTag ) ;
327
+
328
+ var radii = new [ ] { 0f , .5f } ;
329
+ foreach ( var castRadius in radii )
330
+ {
331
+ perception . SphereCastRadius = castRadius ;
332
+ var castInput = perception . GetRayPerceptionInput ( ) ;
333
+ var castOutput = RayPerceptionSensor . Perceive ( castInput ) ;
334
+
335
+ Assert . AreEqual ( 1 , castOutput . RayOutputs . Length ) ;
336
+
337
+ // Expected to hit the cube
338
+ Assert . AreEqual ( "cube" , castOutput . RayOutputs [ 0 ] . HitGameObject . name ) ;
339
+ }
340
+ }
299
341
}
300
342
}
0 commit comments