@@ -39,7 +39,7 @@ public class ControllerInteraction : MonoBehaviour
39
39
private string loadedProfile = null ;
40
40
#endif
41
41
42
- void Awake ( )
42
+ private void Awake ( )
43
43
{
44
44
attachJoint = GetComponent < FixedJoint > ( ) ;
45
45
hasAnimator = animator != null ;
@@ -67,21 +67,21 @@ void Awake()
67
67
SetHandJointsVisible ( false ) ;
68
68
}
69
69
70
- void OnEnable ( )
70
+ private void OnEnable ( )
71
71
{
72
72
controller . OnControllerActive += SetControllerVisible ;
73
73
controller . OnHandActive += SetHandJointsVisible ;
74
74
controller . OnHandUpdate += OnHandUpdate ;
75
75
}
76
76
77
- void OnDisabled ( )
77
+ private void OnDisabled ( )
78
78
{
79
79
controller . OnControllerActive -= SetControllerVisible ;
80
80
controller . OnHandActive -= SetHandJointsVisible ;
81
81
controller . OnHandUpdate -= OnHandUpdate ;
82
82
}
83
83
84
- void Update ( )
84
+ private void Update ( )
85
85
{
86
86
if ( ! controllerVisible && ! handJointsVisible )
87
87
{
@@ -122,7 +122,7 @@ void Update()
122
122
}
123
123
}
124
124
125
- void OnTriggerEnter ( Collider other )
125
+ private void OnTriggerEnter ( Collider other )
126
126
{
127
127
if ( other . gameObject . tag != "Interactable" )
128
128
return ;
@@ -131,28 +131,34 @@ void OnTriggerEnter(Collider other)
131
131
controller . Pulse ( 0.5f , 250 ) ;
132
132
}
133
133
134
- void OnTriggerExit ( Collider other )
134
+ private void OnTriggerExit ( Collider other )
135
135
{
136
136
if ( other . gameObject . tag != "Interactable" )
137
137
return ;
138
138
139
139
contactRigidBodies . Remove ( other . gameObject . GetComponent < Rigidbody > ( ) ) ;
140
140
}
141
141
142
- void SetControllerVisible ( bool visible )
142
+ private void SetControllerVisible ( bool visible )
143
143
{
144
144
controllerVisible = visible ;
145
145
Drop ( ) ;
146
146
#if WEBXR_INPUT_PROFILES
147
+ // We want to use WebXR Input Profiles
147
148
if ( visible && useInputProfile )
148
149
{
149
- if ( inputProfileModel != null )
150
+ if ( inputProfileModel != null && loadedModel )
150
151
{
152
+ // There's a loaded Input Profile Model
151
153
inputProfileModelParent . SetActive ( true ) ;
152
- loadedModel = true ;
154
+ UpdateModelInput ( ) ;
153
155
return ;
154
156
}
155
- LoadInputProfile ( ) ;
157
+ else if ( inputProfileModel == null )
158
+ {
159
+ // There's no loaded Input Profile Model and it's not in loading process
160
+ LoadInputProfile ( ) ;
161
+ }
156
162
}
157
163
else
158
164
{
@@ -165,7 +171,7 @@ void SetControllerVisible(bool visible)
165
171
}
166
172
}
167
173
168
- void SetHandJointsVisible ( bool visible )
174
+ private void SetHandJointsVisible ( bool visible )
169
175
{
170
176
handJointsVisible = visible ;
171
177
Drop ( ) ;
@@ -214,7 +220,7 @@ private void OnHandUpdate(WebXRHandData handData)
214
220
}
215
221
216
222
#if WEBXR_INPUT_PROFILES
217
- void HandleProfilesList ( Dictionary < string , string > profilesList )
223
+ private void HandleProfilesList ( Dictionary < string , string > profilesList )
218
224
{
219
225
if ( profilesList == null || profilesList . Count == 0 )
220
226
{
@@ -223,8 +229,9 @@ void HandleProfilesList(Dictionary<string, string> profilesList)
223
229
hasProfileList = true ;
224
230
}
225
231
226
- void LoadInputProfile ( )
232
+ private void LoadInputProfile ( )
227
233
{
234
+ // Start loading possible profiles for the controller
228
235
var profiles = controller . GetProfiles ( ) ;
229
236
if ( hasProfileList && profiles != null && profiles . Length > 0 )
230
237
{
@@ -239,22 +246,28 @@ private void OnProfileLoaded(bool success)
239
246
{
240
247
LoadInputModel ( ) ;
241
248
}
249
+ // Nothing to do if profile didn't load
242
250
}
243
251
244
- void LoadInputModel ( )
252
+ private void LoadInputModel ( )
245
253
{
246
- inputProfileModel = inputProfileLoader . LoadModelForHand ( loadedProfile , ( InputProfileLoader . Handedness ) controller . hand , HandleModelLoaded ) ;
254
+ inputProfileModel = inputProfileLoader . LoadModelForHand (
255
+ loadedProfile ,
256
+ ( InputProfileLoader . Handedness ) controller . hand ,
257
+ HandleModelLoaded ) ;
247
258
if ( inputProfileModel != null )
248
259
{
260
+ // Update input state while still loading the model
249
261
UpdateModelInput ( ) ;
250
262
}
251
263
}
252
264
253
- void HandleModelLoaded ( bool success )
265
+ private void HandleModelLoaded ( bool success )
254
266
{
255
267
loadedModel = success ;
256
268
if ( loadedModel )
257
269
{
270
+ // Set parent only after successful loading, to not interupt loading in case of disabled object
258
271
var inputProfileModelTransform = inputProfileModel . transform ;
259
272
inputProfileModelTransform . SetParent ( inputProfileModelParent . transform ) ;
260
273
inputProfileModelTransform . localPosition = Vector3 . zero ;
@@ -275,7 +288,7 @@ void HandleModelLoaded(bool success)
275
288
}
276
289
}
277
290
278
- void UpdateModelInput ( )
291
+ private void UpdateModelInput ( )
279
292
{
280
293
for ( int i = 0 ; i < 6 ; i ++ )
281
294
{
@@ -287,12 +300,12 @@ void UpdateModelInput()
287
300
}
288
301
}
289
302
290
- void SetButtonValue ( int index )
303
+ private void SetButtonValue ( int index )
291
304
{
292
305
inputProfileModel . SetButtonValue ( index , controller . GetButtonIndexValue ( index ) ) ;
293
306
}
294
307
295
- public void SetAxisValue ( int index )
308
+ private void SetAxisValue ( int index )
296
309
{
297
310
inputProfileModel . SetAxisValue ( index , controller . GetAxisIndexValue ( index ) ) ;
298
311
}
0 commit comments