Skip to content

Commit 093a382

Browse files
committed
Fixes for Unity 2021 bugs
- Error on XR session end in Unity 2021.2 builds. - Issues with Touch events on AR session in Unity 2021 builds.
1 parent f7d36b5 commit 093a382

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Packages/webxr/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Fixed
99
- hapticActuators didn't work.
10+
- Error on XR session end in Unity 2021.2 builds.
11+
- Issues with Touch events on AR session in Unity 2021 builds.
1012

1113
## [0.13.0] - 2021-10-18
1214
### Added

Packages/webxr/Runtime/Plugins/WebGL/webxr.jspre

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ setTimeout(function () {
3838
this.frameNumber = 0;
3939
this.touchIDs = [];
4040
this.touches = [];
41+
this.eventsNamesToIDs = {};
4142
this.CreateTouch = function (pageElement, xPercentage, yPercentage) {
4243
var touchID = 0;
4344
while (this.touchIDs.includes(touchID))
@@ -58,9 +59,9 @@ setTimeout(function () {
5859
return item !== touch
5960
});
6061
}
61-
this.SendTouchEvent = function(JSEventsObject, eventID, eventName, target, changedTouches) {
62+
this.SendTouchEvent = function(JSEventsObject, eventName, target, changedTouches) {
6263
var touchEvent = new XRTouchEvent(eventName, target, this.touches, this.touches, changedTouches);
63-
JSEventsObject.eventHandlers[eventID].eventListenerFunc(touchEvent);
64+
JSEventsObject.eventHandlers[this.eventsNamesToIDs[eventName]].eventListenerFunc(touchEvent);
6465
}
6566
}
6667

@@ -403,8 +404,9 @@ setTimeout(function () {
403404

404405
this.gameModule.WebXR.OnEndXR();
405406
this.didNotifyUnity = false;
406-
this.canvas.width = this.canvas.parentElement.clientWidth * this.gameModule.asmLibraryArg._JS_SystemInfo_GetPreferredDevicePixelRatio();
407-
this.canvas.height = this.canvas.parentElement.clientHeight * this.gameModule.asmLibraryArg._JS_SystemInfo_GetPreferredDevicePixelRatio();
407+
var pixelRatio = Module.devicePixelRatio || window.devicePixelRatio || 1;
408+
this.canvas.width = this.canvas.parentElement.clientWidth * pixelRatio;
409+
this.canvas.height = this.canvas.parentElement.clientHeight * pixelRatio;
408410

409411
if (this.BrowserObject.pauseAsyncCallbacks) {
410412
this.BrowserObject.pauseAsyncCallbacks();
@@ -426,7 +428,7 @@ setTimeout(function () {
426428
{
427429
var touch = this.xrData.touches[0];
428430
this.xrData.RemoveTouch(touch);
429-
this.xrData.SendTouchEvent(this.JSEventsObject, 8, "touchend", this.canvas, [touch]);
431+
this.xrData.SendTouchEvent(this.JSEventsObject, "touchend", this.canvas, [touch]);
430432
}
431433
}
432434

@@ -491,11 +493,11 @@ setTimeout(function () {
491493
break;
492494
case "selectstart": // 7 touchstart
493495
inputSource.xrTouchObject = this.xrData.CreateTouch(this.canvas, xPercentage, yPercentage);
494-
this.xrData.SendTouchEvent(this.JSEventsObject, 7, "touchstart", this.canvas, [inputSource.xrTouchObject])
496+
this.xrData.SendTouchEvent(this.JSEventsObject, "touchstart", this.canvas, [inputSource.xrTouchObject])
495497
break;
496498
case "selectend": // 8 touchend
497499
this.xrData.RemoveTouch(inputSource.xrTouchObject);
498-
this.xrData.SendTouchEvent(this.JSEventsObject, 8, "touchend", this.canvas, [inputSource.xrTouchObject]);
500+
this.xrData.SendTouchEvent(this.JSEventsObject, "touchend", this.canvas, [inputSource.xrTouchObject]);
499501
inputSource.xrTouchObject = null;
500502
break;
501503
}
@@ -581,6 +583,9 @@ setTimeout(function () {
581583

582584
var thisXRMananger = this;
583585
this.JSEventsObject = this.gameModule.WebXR.GetJSEventsObject();
586+
for (var i = 0; i < this.JSEventsObject.eventHandlers.length; i++) {
587+
this.xrData.eventsNamesToIDs[this.JSEventsObject.eventHandlers[i].eventTypeString] = i;
588+
}
584589
this.BrowserObject = this.gameModule.WebXR.GetBrowserObject();
585590
this.BrowserObject.requestAnimationFrame = function (func) {
586591
if (thisXRMananger.xrSession && thisXRMananger.xrSession.isInSession) {
@@ -818,7 +823,7 @@ setTimeout(function () {
818823
}
819824
}
820825
if (touchesToSend.length > 0) {
821-
this.xrData.SendTouchEvent(this.JSEventsObject, 9, "touchmove", this.canvas, touchesToSend);
826+
this.xrData.SendTouchEvent(this.JSEventsObject, "touchmove", this.canvas, touchesToSend);
822827
for (var i = 0; i < touchesToSend.length; i++) {
823828
touchesToSend[i].ResetMovement();
824829
}

0 commit comments

Comments
 (0)