Skip to content

Commit 6bd8c96

Browse files
committed
Small fixes and handle input Profile Loader in editor
1 parent d62eac2 commit 6bd8c96

File tree

4 files changed

+78
-21
lines changed

4 files changed

+78
-21
lines changed

Packages/webxr-interactions/Runtime/Scripts/ControllerInteraction.cs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ControllerInteraction : MonoBehaviour
3939
private string loadedProfile = null;
4040
#endif
4141

42-
void Awake()
42+
private void Awake()
4343
{
4444
attachJoint = GetComponent<FixedJoint>();
4545
hasAnimator = animator != null;
@@ -67,21 +67,21 @@ void Awake()
6767
SetHandJointsVisible(false);
6868
}
6969

70-
void OnEnable()
70+
private void OnEnable()
7171
{
7272
controller.OnControllerActive += SetControllerVisible;
7373
controller.OnHandActive += SetHandJointsVisible;
7474
controller.OnHandUpdate += OnHandUpdate;
7575
}
7676

77-
void OnDisabled()
77+
private void OnDisabled()
7878
{
7979
controller.OnControllerActive -= SetControllerVisible;
8080
controller.OnHandActive -= SetHandJointsVisible;
8181
controller.OnHandUpdate -= OnHandUpdate;
8282
}
8383

84-
void Update()
84+
private void Update()
8585
{
8686
if (!controllerVisible && !handJointsVisible)
8787
{
@@ -122,7 +122,7 @@ void Update()
122122
}
123123
}
124124

125-
void OnTriggerEnter(Collider other)
125+
private void OnTriggerEnter(Collider other)
126126
{
127127
if (other.gameObject.tag != "Interactable")
128128
return;
@@ -131,28 +131,34 @@ void OnTriggerEnter(Collider other)
131131
controller.Pulse(0.5f, 250);
132132
}
133133

134-
void OnTriggerExit(Collider other)
134+
private void OnTriggerExit(Collider other)
135135
{
136136
if (other.gameObject.tag != "Interactable")
137137
return;
138138

139139
contactRigidBodies.Remove(other.gameObject.GetComponent<Rigidbody>());
140140
}
141141

142-
void SetControllerVisible(bool visible)
142+
private void SetControllerVisible(bool visible)
143143
{
144144
controllerVisible = visible;
145145
Drop();
146146
#if WEBXR_INPUT_PROFILES
147+
// We want to use WebXR Input Profiles
147148
if (visible && useInputProfile)
148149
{
149-
if (inputProfileModel != null)
150+
if (inputProfileModel != null && loadedModel)
150151
{
152+
// There's a loaded Input Profile Model
151153
inputProfileModelParent.SetActive(true);
152-
loadedModel = true;
154+
UpdateModelInput();
153155
return;
154156
}
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+
}
156162
}
157163
else
158164
{
@@ -165,7 +171,7 @@ void SetControllerVisible(bool visible)
165171
}
166172
}
167173

168-
void SetHandJointsVisible(bool visible)
174+
private void SetHandJointsVisible(bool visible)
169175
{
170176
handJointsVisible = visible;
171177
Drop();
@@ -214,7 +220,7 @@ private void OnHandUpdate(WebXRHandData handData)
214220
}
215221

216222
#if WEBXR_INPUT_PROFILES
217-
void HandleProfilesList(Dictionary<string, string> profilesList)
223+
private void HandleProfilesList(Dictionary<string, string> profilesList)
218224
{
219225
if (profilesList == null || profilesList.Count == 0)
220226
{
@@ -223,8 +229,9 @@ void HandleProfilesList(Dictionary<string, string> profilesList)
223229
hasProfileList = true;
224230
}
225231

226-
void LoadInputProfile()
232+
private void LoadInputProfile()
227233
{
234+
// Start loading possible profiles for the controller
228235
var profiles = controller.GetProfiles();
229236
if (hasProfileList && profiles != null && profiles.Length > 0)
230237
{
@@ -239,22 +246,28 @@ private void OnProfileLoaded(bool success)
239246
{
240247
LoadInputModel();
241248
}
249+
// Nothing to do if profile didn't load
242250
}
243251

244-
void LoadInputModel()
252+
private void LoadInputModel()
245253
{
246-
inputProfileModel = inputProfileLoader.LoadModelForHand(loadedProfile, (InputProfileLoader.Handedness)controller.hand, HandleModelLoaded);
254+
inputProfileModel = inputProfileLoader.LoadModelForHand(
255+
loadedProfile,
256+
(InputProfileLoader.Handedness)controller.hand,
257+
HandleModelLoaded);
247258
if (inputProfileModel != null)
248259
{
260+
// Update input state while still loading the model
249261
UpdateModelInput();
250262
}
251263
}
252264

253-
void HandleModelLoaded(bool success)
265+
private void HandleModelLoaded(bool success)
254266
{
255267
loadedModel = success;
256268
if (loadedModel)
257269
{
270+
// Set parent only after successful loading, to not interupt loading in case of disabled object
258271
var inputProfileModelTransform = inputProfileModel.transform;
259272
inputProfileModelTransform.SetParent(inputProfileModelParent.transform);
260273
inputProfileModelTransform.localPosition = Vector3.zero;
@@ -275,7 +288,7 @@ void HandleModelLoaded(bool success)
275288
}
276289
}
277290

278-
void UpdateModelInput()
291+
private void UpdateModelInput()
279292
{
280293
for (int i = 0; i < 6; i++)
281294
{
@@ -287,12 +300,12 @@ void UpdateModelInput()
287300
}
288301
}
289302

290-
void SetButtonValue(int index)
303+
private void SetButtonValue(int index)
291304
{
292305
inputProfileModel.SetButtonValue(index, controller.GetButtonIndexValue(index));
293306
}
294307

295-
public void SetAxisValue(int index)
308+
private void SetAxisValue(int index)
296309
{
297310
inputProfileModel.SetAxisValue(index, controller.GetAxisIndexValue(index));
298311
}

Packages/webxr-interactions/Samples~/Desert/Prefabs/WebXRCameraSet.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ MonoBehaviour:
18851885
m_Script: {fileID: 11500000, guid: 580e3dd931df2bd42b042a7e8fde2aa8, type: 3}
18861886
m_Name:
18871887
m_EditorClassIdentifier:
1888-
animator: {fileID: 95292425453911886}
1888+
animator: {fileID: 95219300520550374}
18891889
animationStateName: Take
18901890
controllerVisuals:
18911891
- {fileID: 1644997114004198}

Packages/webxr/Runtime/Scripts/WebXRController.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,46 @@ private void HandleInputDevicesConnected(InputDevice device)
457457
{
458458
hapticCapabilities = capabilities;
459459
}
460+
profiles = null;
461+
// TODO: Find a better way to get device profile
462+
if (device.manufacturer == "Oculus")
463+
{
464+
profiles = new string[]{"oculus-touch-v2"};
465+
}
466+
else
467+
{
468+
string profileName = "generic";
469+
bool addedFeatures = false;
470+
float tempFloat = 0;
471+
Vector2 tempVec2 = Vector2.zero;
472+
if (device.TryGetFeatureValue(CommonUsages.trigger, out tempFloat))
473+
{
474+
profileName += "-trigger";
475+
addedFeatures = true;
476+
}
477+
if (device.TryGetFeatureValue(CommonUsages.grip, out tempFloat))
478+
{
479+
profileName += "-squeeze";
480+
addedFeatures = true;
481+
}
482+
if (device.TryGetFeatureValue(CommonUsages.secondary2DAxis, out tempVec2))
483+
{
484+
profileName += "-touchpad";
485+
addedFeatures = true;
486+
}
487+
if (device.TryGetFeatureValue(CommonUsages.primary2DAxis, out tempVec2))
488+
{
489+
profileName += "-thumbstick";
490+
addedFeatures = true;
491+
}
492+
if (!addedFeatures)
493+
{
494+
profileName += "-button";
495+
}
496+
profiles = new string[]{profileName};
497+
Debug.LogError(profileName);
498+
}
499+
TryUpdateButtons();
460500
SetControllerActive(true);
461501
}
462502
}

Packages/webxr/Runtime/Scripts/WebXRControllerData.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public class WebXRHitPoseData
8484
public Quaternion rotation;
8585
}
8686

87-
public enum WebXRControllerHand { NONE, LEFT, RIGHT };
87+
public enum WebXRControllerHand {
88+
NONE = 0,
89+
LEFT = 1,
90+
RIGHT = 2
91+
}
8892

8993
[System.Serializable]
9094
public class WebXRControllerButton

0 commit comments

Comments
 (0)