@@ -7,21 +7,60 @@ namespace VRTK.Examples.Utilities
7
7
[ ExecuteInEditMode ]
8
8
public class VRTKExample_FixSetup : MonoBehaviour
9
9
{
10
+ public bool forceOculusFloorLevel = true ;
11
+ protected bool trackingLevelFloor = false ;
12
+
10
13
public virtual void ApplyFixes ( )
11
14
{
12
15
FixOculus ( ) ;
13
16
}
14
17
15
18
protected virtual void Awake ( )
16
19
{
17
- ApplyFixes ( ) ;
20
+
21
+ if ( Application . isEditor && ! Application . isPlaying )
22
+ {
23
+ ApplyFixes ( ) ;
24
+ }
25
+ }
26
+
27
+ protected virtual void Update ( )
28
+ {
29
+ FixTrackingType ( ) ;
30
+ }
31
+
32
+ protected virtual void FixTrackingType ( )
33
+ {
34
+ #if VRTK_DEFINE_SDK_OCULUS
35
+ if ( forceOculusFloorLevel && ! trackingLevelFloor )
36
+ {
37
+ GameObject overManagerGO = GameObject . Find ( "[VRTK_SDKManager]/[VRTK_SDKSetups]/Oculus/OVRCameraRig" ) ;
38
+ if ( overManagerGO != null )
39
+ {
40
+ OVRManager ovrManager = overManagerGO . GetComponent < OVRManager > ( ) ;
41
+ if ( ovrManager != null )
42
+ {
43
+ ovrManager . trackingOriginType = OVRManager . TrackingOrigin . FloorLevel ;
44
+ trackingLevelFloor = true ;
45
+ Debug . Log ( "Forced Oculus Tracking to Floor Level" ) ;
46
+ }
47
+ }
48
+ }
49
+ #endif
18
50
}
19
51
20
52
protected virtual void FixOculus ( )
21
53
{
22
54
#if VRTK_DEFINE_SDK_OCULUS
23
55
string oculusPath = "[VRTK_SDKManager]/[VRTK_SDKSetups]/Oculus" ;
24
56
GameObject oculusSDK = GameObject . Find ( oculusPath ) ;
57
+
58
+ if ( oculusSDK == null || oculusSDK . GetComponentInChildren < OVRManager > ( ) != null )
59
+ {
60
+ Debug . Log ( "No Oculus Repaired Required" ) ;
61
+ return ;
62
+ }
63
+
25
64
GameObject currentRig = GameObject . Find ( oculusPath + "/OVRCameraRig" ) ;
26
65
GameObject currentAvatar = GameObject . Find ( oculusPath + "/LocalAvatar" ) ;
27
66
VRTK_SDKSetup oculusSetup = oculusSDK . GetComponent < VRTK_SDKSetup > ( ) ;
@@ -35,30 +74,47 @@ protected virtual void FixOculus()
35
74
DestroyImmediate ( currentAvatar ) ;
36
75
}
37
76
38
- GameObject ovrCameraRig = PrefabUtility . InstantiatePrefab ( ( GameObject ) AssetDatabase . LoadAssetAtPath ( "Assets/Oculus/VR/Prefabs/OVRCameraRig.prefab" , typeof ( GameObject ) ) ) as GameObject ;
77
+ GameObject ovrCameraRig = null ;
78
+ GameObject ovrCameraRigToInstantiate = ( GameObject ) AssetDatabase . LoadAssetAtPath ( "Assets/Oculus/VR/Prefabs/OVRCameraRig.prefab" , typeof ( GameObject ) ) ;
79
+ if ( ovrCameraRigToInstantiate != null )
80
+ {
81
+ ovrCameraRig = Instantiate ( ovrCameraRigToInstantiate ) as GameObject ;
82
+ }
39
83
if ( ovrCameraRig != null )
40
84
{
85
+ ovrCameraRig . name = ovrCameraRig . name . Replace ( "(Clone)" , "" ) ;
41
86
ovrCameraRig . transform . SetParent ( oculusSDK . transform ) ;
42
- ovrCameraRig . SetActive ( false ) ;
87
+ ovrCameraRig . SetActive ( true ) ;
43
88
oculusSetup . actualBoundaries = ovrCameraRig ;
44
89
oculusSetup . actualHeadset = GameObject . Find ( oculusPath + "/OVRCameraRig/TrackingSpace/CenterEyeAnchor" ) ;
45
90
oculusSetup . actualLeftController = GameObject . Find ( oculusPath + "/OVRCameraRig/TrackingSpace/LeftHandAnchor" ) ;
46
91
oculusSetup . actualRightController = GameObject . Find ( oculusPath + "/OVRCameraRig/TrackingSpace/RightHandAnchor" ) ;
47
- OVRManager ovrManager = ovrCameraRig . GetComponent < OVRManager > ( ) ;
48
- ovrManager . trackingOriginType = OVRManager . TrackingOrigin . FloorLevel ;
49
92
Debug . Log ( "Successfully repaired Oculus OVRCameraRig prefab" ) ;
50
93
}
51
94
52
- GameObject ovrAvatar = PrefabUtility . InstantiatePrefab ( ( GameObject ) AssetDatabase . LoadAssetAtPath ( "Assets/Oculus/Avatar/Content/Prefabs/LocalAvatar.prefab" , typeof ( GameObject ) ) ) as GameObject ;
95
+ GameObject ovrAvatar = null ;
96
+ GameObject ovrAvatarToInstantiate = ( GameObject ) AssetDatabase . LoadAssetAtPath ( "Assets/Oculus/Avatar/Content/Prefabs/LocalAvatar.prefab" , typeof ( GameObject ) ) ;
97
+ if ( ovrAvatarToInstantiate != null )
98
+ {
99
+ ovrAvatar = Instantiate ( ovrAvatarToInstantiate ) as GameObject ;
100
+ }
101
+
53
102
if ( ovrAvatar == null )
54
103
{
55
104
//legacy location
56
- ovrAvatar = PrefabUtility . InstantiatePrefab ( ( GameObject ) AssetDatabase . LoadAssetAtPath ( "Assets/OvrAvatar/Content/Prefabs/LocalAvatar.prefab" , typeof ( GameObject ) ) ) as GameObject ;
105
+ ovrAvatarToInstantiate = ( GameObject ) AssetDatabase . LoadAssetAtPath ( "Assets/OvrAvatar/Content/Prefabs/LocalAvatar.prefab" , typeof ( GameObject ) ) ;
106
+ if ( ovrAvatarToInstantiate != null )
107
+ {
108
+ ovrAvatar = Instantiate ( ovrAvatarToInstantiate ) as GameObject ;
109
+ }
57
110
}
58
111
if ( ovrAvatar != null )
59
112
{
113
+ OvrAvatar avatarScript = ovrAvatar . GetComponent < OvrAvatar > ( ) ;
114
+ avatarScript . StartWithControllers = true ;
115
+ ovrAvatar . name = ovrAvatar . name . Replace ( "(Clone)" , "" ) ;
60
116
ovrAvatar . transform . SetParent ( oculusSDK . transform ) ;
61
- ovrAvatar . SetActive ( false ) ;
117
+ ovrAvatar . SetActive ( true ) ;
62
118
oculusSetup . modelAliasLeftController = GameObject . Find ( oculusPath + "/LocalAvatar/controller_left" ) ;
63
119
oculusSetup . modelAliasRightController = GameObject . Find ( oculusPath + "/LocalAvatar/controller_right" ) ;
64
120
GameObject . Find ( oculusPath + "/LocalAvatar/hand_left" ) . SetActive ( false ) ;
0 commit comments