@@ -57,7 +57,7 @@ private BoundsControl InstantiateSceneAndDefaultBbox()
5757 p =>
5858 {
5959 p . position = Vector3 . zero ;
60- p . LookAt ( cube . transform . position ) ;
60+ p . LookAt ( boundsControlStartCenter ) ;
6161 } ) ;
6262
6363 bbox . transform . localScale = boundsControlStartScale ;
@@ -335,6 +335,117 @@ public IEnumerator DisableObject()
335335 Assert . AreEqual ( afterTransformScale , bbox . transform . localScale ) ;
336336 }
337337
338+ /// <summary>
339+ /// Tests proximity scaling on scale handles of bounds control
340+ /// Verifies default behavior of handles with effect enabled / disabled as well as custom runtime configured scaling / distance values
341+ /// </summary>
342+ [ UnityTest ]
343+ public IEnumerator ProximityOnScaleHandles ( )
344+ {
345+ var bbox = InstantiateSceneAndDefaultBbox ( ) ;
346+ yield return VerifyInitialBoundsCorrect ( bbox ) ;
347+
348+ // 1. test no proximity scaling active per default
349+ ScaleHandlesConfiguration scaleHandleConfig = bbox . ScaleHandlesConfiguration ;
350+ Vector3 defaultHandleSize = Vector3 . one * scaleHandleConfig . HandleSize ;
351+
352+ Vector3 initialHandPosition = new Vector3 ( 0 , 0 , 0f ) ;
353+ // this is specific to scale handles
354+ Transform scaleHandle = bbox . gameObject . transform . Find ( "rigRoot/corner_3" ) ;
355+ Transform proximityScaledVisual = scaleHandle . GetChild ( 0 ) ? . GetChild ( 0 ) ;
356+ var frontRightCornerPos = scaleHandle . position ; // front right corner is corner
357+ Assert . IsNotNull ( proximityScaledVisual , "Couldn't get visual gameobject for scale handle" ) ;
358+ Assert . IsTrue ( proximityScaledVisual . name == "visuals" , "scale visual has unexpected name" ) ;
359+
360+ yield return null ;
361+ // verify no proximity scaling applied per default
362+ Assert . AreEqual ( proximityScaledVisual . localScale , defaultHandleSize , "Handle was scaled even though proximity effect wasn't active" ) ;
363+ TestHand hand = new TestHand ( Handedness . Left ) ;
364+ Vector3 initialScale = bbox . transform . localScale ;
365+
366+ // Hands grab object at initial position
367+ yield return hand . Show ( initialHandPosition ) ;
368+ yield return hand . SetGesture ( ArticulatedHandPose . GestureId . OpenSteadyGrabPoint ) ;
369+ yield return hand . MoveTo ( frontRightCornerPos ) ;
370+ yield return null ;
371+
372+ // we're in poximity scaling range - check if proximity scaling wasn't applied
373+ Assert . AreEqual ( proximityScaledVisual . localScale , defaultHandleSize , "Handle was scaled even though proximity effect wasn't active" ) ;
374+
375+ //// reset hand
376+ yield return hand . MoveTo ( initialHandPosition ) ;
377+
378+ // 2. enable proximity scaling and test defaults
379+ ProximityEffectConfiguration proximityConfig = bbox . HandleProximityEffectConfiguration ;
380+ proximityConfig . ProximityEffectActive = true ;
381+ proximityConfig . CloseGrowRate = 1.0f ;
382+ proximityConfig . MediumGrowRate = 1.0f ;
383+ proximityConfig . FarGrowRate = 1.0f ;
384+ bbox . CreateRig ( ) ;
385+ yield return null ; // wait so rig gameobjects get recreated
386+ yield return TestCurrentProximityConfiguration ( bbox , hand , "Defaults" ) ;
387+
388+ // reset hand
389+ yield return hand . MoveTo ( initialHandPosition ) ;
390+
391+ // 3. now test custom configuration is applied during runtime
392+ proximityConfig . CloseScale = 4.0f ;
393+ proximityConfig . MediumScale = 3.0f ;
394+ proximityConfig . FarScale = 2.0f ;
395+
396+ proximityConfig . ObjectMediumProximity = 0.2f ;
397+ proximityConfig . ObjectCloseProximity = 0.1f ;
398+
399+ bbox . CreateRig ( ) ;
400+ yield return null ; // wait so rig gameobjects get recreated
401+ yield return TestCurrentProximityConfiguration ( bbox , hand , "Custom runtime config max" ) ;
402+ }
403+
404+ /// <summary>
405+ /// This tests far, medium and close proximity scaling on scale handles by moving the test hand in the corresponding distance ranges
406+ /// </summary>
407+ /// <param name="bbox">Bounds Control to test on</param>
408+ /// <param name="hand">Test hand to use for testing proximity to handle</param>
409+ private IEnumerator TestCurrentProximityConfiguration ( BoundsControl bbox , TestHand hand , string testDescription )
410+ {
411+ // get config and scaling handle
412+ ScaleHandlesConfiguration scaleHandleConfig = bbox . ScaleHandlesConfiguration ;
413+ Vector3 defaultHandleSize = Vector3 . one * scaleHandleConfig . HandleSize ;
414+ Transform scaleHandle = bbox . gameObject . transform . Find ( "rigRoot/corner_3" ) ;
415+ Transform proximityScaledVisual = scaleHandle . GetChild ( 0 ) ? . GetChild ( 0 ) ;
416+ var frontRightCornerPos = scaleHandle . position ;
417+ // check far scale applied
418+ ProximityEffectConfiguration proximityConfig = bbox . HandleProximityEffectConfiguration ;
419+ Vector3 expectedFarScale = defaultHandleSize * proximityConfig . FarScale ;
420+ Assert . AreEqual ( proximityScaledVisual . localScale , expectedFarScale , testDescription + " - Proximity far scale wasn't applied to handle" ) ;
421+
422+ // move into medium range and check if scale was applied
423+ Vector3 mediumProximityTestDist = frontRightCornerPos ;
424+ mediumProximityTestDist . x += proximityConfig . ObjectMediumProximity ;
425+ yield return hand . MoveTo ( mediumProximityTestDist ) ;
426+ Vector3 expectedMediumScale = defaultHandleSize * proximityConfig . MediumScale ;
427+ Assert . AreEqual ( proximityScaledVisual . localScale , expectedMediumScale , testDescription + " - Proximity medium scale wasn't applied to handle" ) ;
428+
429+ // move into close scale range and check if scale was applied
430+ Vector3 closeProximityTestDir = frontRightCornerPos ;
431+ closeProximityTestDir . x += proximityConfig . ObjectCloseProximity ;
432+ yield return hand . MoveTo ( closeProximityTestDir ) ;
433+ Vector3 expectedCloseScale = defaultHandleSize * proximityConfig . CloseScale ;
434+ Assert . AreEqual ( proximityScaledVisual . localScale , expectedCloseScale , testDescription + " - Proximity close scale wasn't applied to handle" ) ;
435+
436+ // move out of close scale again - should fall back to medium proximity
437+ closeProximityTestDir = mediumProximityTestDist ;
438+ yield return hand . MoveTo ( closeProximityTestDir ) ;
439+ Assert . AreEqual ( proximityScaledVisual . localScale , expectedMediumScale , testDescription + " - Proximity medium scale wasn't applied to handle" ) ;
440+
441+ // move out of medium proximity and check if far scaling is applied
442+ mediumProximityTestDist = Vector3 . zero ;
443+ yield return hand . MoveTo ( mediumProximityTestDist ) ;
444+ Assert . AreEqual ( proximityScaledVisual . localScale , expectedFarScale , testDescription + " - Proximity far scale wasn't applied to handle" ) ;
445+
446+ yield return null ;
447+ }
448+
338449 /// <summary>
339450 /// Tests setting a target in code that is a different gameobject than the gameobject the bounds control component is attached to
340451 /// </summary>
0 commit comments