44using UnrealEngine . Framework ;
55
66namespace UnrealEngine . Tests {
7- public class VirtualReality : ISystem {
8- private Pawn pawnVR ;
9- private SceneComponent body ;
10- private MotionControllerComponent leftHand ;
11- private MotionControllerComponent rightHand ;
12-
13- public VirtualReality ( ) {
14- pawnVR = new ( "PawnVR" ) ;
15- body = new ( pawnVR , "Root" ) ;
16- leftHand = new ( pawnVR , "LeftHand" ) ;
17- rightHand = new ( pawnVR , "RightHand" ) ;
18- }
19-
20- public void OnBeginPlay ( ) {
21- Camera mainCamera = World . GetActor < Camera > ( "MainCamera" ) ;
22-
23- mainCamera . GetComponent < CameraComponent > ( ) . LockToHeadMountedDisplay = true ;
24-
25- PlayerController playerController = World . GetFirstPlayerController ( ) ;
26-
27- playerController . SetViewTarget ( mainCamera ) ;
28- playerController . Possess ( pawnVR ) ;
29-
30- leftHand . DisplayDeviceModel = true ;
31- leftHand . SetTrackingMotionSource ( "Left" ) ;
32-
33- rightHand . DisplayDeviceModel = true ;
34- rightHand . SetTrackingMotionSource ( "Right" ) ;
35- }
36-
37- public void OnTick ( float deltaTime ) {
38- Debug . AddOnScreenMessage ( 1 , 3.0f , Color . Yellow , "Head-mounted display is connected: " + HeadMountedDisplay . IsConnected ) ;
39- Debug . AddOnScreenMessage ( 2 , 3.0f , Color . Yellow , "Device enabled: " + HeadMountedDisplay . Enabled ) ;
40- Debug . AddOnScreenMessage ( 3 , 3.0f , Color . Yellow , "Device name: " + HeadMountedDisplay . DeviceName ) ;
41- }
42-
43- public void OnEndPlay ( ) => Debug . ClearOnScreenMessages ( ) ;
44- }
7+ public class VirtualReality : ISystem {
8+ private Pawn pawnVR ;
9+ private SceneComponent body ;
10+ private MotionControllerComponent leftHand ;
11+ private MotionControllerComponent rightHand ;
12+
13+ public VirtualReality ( ) {
14+ pawnVR = new ( "PawnVR" ) ;
15+ body = new ( pawnVR , "Root" ) ;
16+ leftHand = new ( pawnVR , "LeftHand" ) ;
17+ rightHand = new ( pawnVR , "RightHand" ) ;
18+ }
19+
20+ public void OnBeginPlay ( ) {
21+ Camera mainCamera = World . GetActor < Camera > ( "MainCamera" ) ;
22+
23+ mainCamera . GetComponent < CameraComponent > ( ) . LockToHeadMountedDisplay = true ;
24+
25+ PlayerController playerController = World . GetFirstPlayerController ( ) ;
26+
27+ playerController . SetViewTarget ( mainCamera ) ;
28+ playerController . Possess ( pawnVR ) ;
29+
30+ leftHand . DisplayDeviceModel = true ;
31+ leftHand . SetTrackingMotionSource ( "Left" ) ;
32+
33+ rightHand . DisplayDeviceModel = true ;
34+ rightHand . SetTrackingMotionSource ( "Right" ) ;
35+ }
36+
37+ public void OnTick ( float deltaTime ) {
38+ Debug . AddOnScreenMessage ( 1 , 3.0f , Color . Yellow , "Head-mounted display is connected: " + HeadMountedDisplay . IsConnected ) ;
39+ Debug . AddOnScreenMessage ( 2 , 3.0f , Color . Yellow , "Device enabled: " + HeadMountedDisplay . Enabled ) ;
40+ Debug . AddOnScreenMessage ( 3 , 3.0f , Color . Yellow , "Device name: " + HeadMountedDisplay . DeviceName ) ;
41+ Debug . AddOnScreenMessage ( 4 , 3.0f , Color . Orange , "Left motion controller is tracked: " + leftHand . IsTracked ) ;
42+ Debug . AddOnScreenMessage ( 5 , 3.0f , Color . Orange , "Right motion controller is tracked: " + rightHand . IsTracked ) ;
43+ }
44+
45+ public void OnEndPlay ( ) => Debug . ClearOnScreenMessages ( ) ;
46+ }
4547}
0 commit comments