@@ -28,20 +28,42 @@ public void Initialize(bool isLeftHand)
2828 m_ovrSkeleton = gameObject . AddComponent < OVRSkeleton > ( ) ;
2929 UpdateOvrSkeleton ( ) ;
3030
31- FieldInfo updateRootScaleField = m_ovrSkeleton . GetType ( ) . GetField ( "_updateRootScale" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
32- updateRootScaleField . SetValue ( m_ovrSkeleton , true ) ;
31+ var dataProviderField = typeof ( OVRSkeleton ) . GetField ( "_dataProvider" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
32+ var searchDataProviderMethod = typeof ( OVRSkeleton ) . GetMethod ( "SearchSkeletonDataProvider" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
33+ var updateRootScaleField = typeof ( OVRSkeleton ) . GetField ( "_updateRootScale" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
34+ var updateRootPoseField = typeof ( OVRSkeleton ) . GetField ( "_updateRootPose" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
35+ var skeletonInitializeMethod = typeof ( OVRSkeleton ) . GetMethod ( "Initialize" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
3336
34- FieldInfo updateRootPoseField = m_ovrSkeleton . GetType ( ) . GetField ( "_updateRootPose" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
35- updateRootPoseField . SetValue ( m_ovrSkeleton , false ) ;
37+ if ( dataProviderField != null && searchDataProviderMethod != null )
38+ {
39+ dataProviderField . SetValue ( m_ovrSkeleton , searchDataProviderMethod . Invoke ( m_ovrSkeleton , new object [ ] { } ) ) ;
40+ }
41+
42+ if ( updateRootScaleField != null )
43+ {
44+ updateRootScaleField . SetValue ( m_ovrSkeleton , true ) ;
45+ }
46+
47+ if ( updateRootPoseField != null )
48+ {
49+ updateRootPoseField . SetValue ( m_ovrSkeleton , false ) ;
50+ }
51+
52+ if ( skeletonInitializeMethod != null )
53+ {
54+ skeletonInitializeMethod . Invoke ( m_ovrSkeleton , new object [ ] { } ) ;
55+ }
3656
37- MethodInfo skeletonInitializeMethod = m_ovrSkeleton . GetType ( ) . GetMethod ( "Initialize" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
38- skeletonInitializeMethod . Invoke ( m_ovrSkeleton , new object [ ] { } ) ;
3957
4058 m_ovrMesh = gameObject . AddComponent < OVRMesh > ( ) ;
4159 UpdateOvrMesh ( ) ;
4260
43- MethodInfo meshInitializeMethod = m_ovrMesh . GetType ( ) . GetMethod ( "Initialize" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
44- meshInitializeMethod . Invoke ( m_ovrMesh , new object [ ] { m_isLeftHand ? OVRMesh . MeshType . HandLeft : OVRMesh . MeshType . HandRight } ) ;
61+ var meshInitializeMethod = typeof ( OVRMesh ) . GetMethod ( "Initialize" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
62+
63+ if ( meshInitializeMethod != null )
64+ {
65+ meshInitializeMethod . Invoke ( m_ovrMesh , new object [ ] { m_isLeftHand ? OVRMesh . MeshType . HandLeft : OVRMesh . MeshType . HandRight } ) ;
66+ }
4567
4668 gameObject . AddComponent < OVRMeshRenderer > ( ) ;
4769
@@ -72,42 +94,42 @@ private void UpdateHand()
7294 UpdateOvrMesh ( ) ;
7395 }
7496
97+ private static FieldInfo OVRHand_HandType_Field = typeof ( OVRHand ) . GetField ( "HandType" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
7598 private void UpdateOvrHand ( )
7699 {
77- try
100+ if ( OVRHand_HandType_Field != null )
78101 {
79- FieldInfo handTypeField = m_ovrHand . GetType ( ) . GetField ( "HandType" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
80- handTypeField . SetValue ( m_ovrHand , m_isLeftHand ? OVRHand . Hand . HandLeft : OVRHand . Hand . HandRight ) ;
102+ OVRHand_HandType_Field . SetValue ( m_ovrHand , m_isLeftHand ? OVRHand . Hand . HandLeft : OVRHand . Hand . HandRight ) ;
81103 }
82- catch ( Exception e )
104+ else
83105 {
84- Debug . LogError ( "Failed to update OVRHand: " + e ) ;
106+ Debug . LogError ( "Failed to update OVRHand: OVRHand_HandType_Field not found" ) ;
85107 }
86108 }
87109
110+ private static FieldInfo OVRSkeleton_skeletonType_Field = typeof ( OVRSkeleton ) . GetField ( "_skeletonType" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
88111 private void UpdateOvrSkeleton ( )
89112 {
90- try
113+ if ( OVRSkeleton_skeletonType_Field != null )
91114 {
92- FieldInfo skeletonTypeField = m_ovrSkeleton . GetType ( ) . GetField ( "_skeletonType" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
93- skeletonTypeField . SetValue ( m_ovrSkeleton , m_isLeftHand ? OVRSkeleton . SkeletonType . HandLeft : OVRSkeleton . SkeletonType . HandRight ) ;
115+ OVRSkeleton_skeletonType_Field . SetValue ( m_ovrSkeleton , m_isLeftHand ? OVRSkeleton . SkeletonType . HandLeft : OVRSkeleton . SkeletonType . HandRight ) ;
94116 }
95- catch ( Exception e )
117+ else
96118 {
97- Debug . LogError ( "Failed to update OVRHand: " + e ) ;
119+ Debug . LogError ( "Failed to update OvrSkeleton: OVRSkeleton_skeletonType_Field not found" ) ;
98120 }
99121 }
100122
123+ private static FieldInfo OVRMesh_meshType_Field = typeof ( OVRMesh ) . GetField ( "_meshType" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
101124 private void UpdateOvrMesh ( )
102125 {
103- try
126+ if ( OVRMesh_meshType_Field != null )
104127 {
105- FieldInfo meshTypeField = m_ovrMesh . GetType ( ) . GetField ( "_meshType" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
106- meshTypeField . SetValue ( m_ovrMesh , m_isLeftHand ? OVRMesh . MeshType . HandLeft : OVRMesh . MeshType . HandRight ) ;
128+ OVRMesh_meshType_Field . SetValue ( m_ovrMesh , m_isLeftHand ? OVRMesh . MeshType . HandLeft : OVRMesh . MeshType . HandRight ) ;
107129 }
108- catch ( Exception e )
130+ else
109131 {
110- Debug . LogError ( "Failed to update OVRHand: " + e ) ;
132+ Debug . LogError ( "Failed to update OvrMesh: OVRMesh_meshType_Field not found" ) ;
111133 }
112134 }
113135#else
0 commit comments