Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceOrientationEvent.requestPermission() #168

Open
psusset opened this issue Jul 21, 2021 · 8 comments
Open

DeviceOrientationEvent.requestPermission() #168

psusset opened this issue Jul 21, 2021 · 8 comments

Comments

@psusset
Copy link

psusset commented Jul 21, 2021

Hello,

In order to make this plugin work on iOS, you need to ask user permission for device orientation capture.
To do that, we need to insert the following code in the requestSession action.

navigator.xr.requestSession('immersive-vr', {
requiredFeatures: thisXRMananger.gameModule.WebXR.Settings.VRRequiredReferenceSpace,
optionalFeatures: thisXRMananger.gameModule.WebXR.Settings.VROptionalFeatures
}).then(async (session) => {
if (typeof(DeviceOrientationEvent) !== "undefined" && typeof(DeviceOrientationEvent).requestPermission === 'function')
{
DeviceOrientationEvent.requestPermission()
.then(response => {
if (response === 'granted') {
session.isImmersive = true;
session.isInSession = true;
session.isAR = false;
thisXRMananger.xrSession = session;
thisXRMananger.onSessionStarted(session);
}
}).catch(function (error) {
thisXRMananger.BrowserObject.resumeAsyncCallbacks();
thisXRMananger.BrowserObject.mainLoop.resume();
});
} else {
session.isImmersive = true;
session.isInSession = true;
session.isAR = false;
thisXRMananger.xrSession = session;
thisXRMananger.onSessionStarted(session);
}
});

@De-Panther
Copy link
Owner

Thanks for the feedback.
I don't have an iOS device, so I don't have a way to test it on those.

iOS in general doesn't support WebXR.
I think that it does support WebVR, or some version of it with cardboard, but it's all using the WebXR Polyfill.
So if the DeviceOrientationEvent is required, better report about it at the WebXR Polyfill repo, as I see you did
immersive-web/webxr-polyfill#161

@psusset
Copy link
Author

psusset commented Jul 23, 2021

In deed, it works with polyfill on iOS.
I test this code on your plugin and it works well on iOS (at least for my purpose - cardboard with reticle). For those who want to support WebXR on iOS with this plugin, you will also need to change the html template so the unity can use all the screen in landscape mode.

@GittyUpperNinja
Copy link

OMG THANK YOU SO MUCH

@jamwitk
Copy link

jamwitk commented Feb 14, 2022

Hi @psusset , it works for VR button in web site page but not in scene button. How do you use it for in scene button?

@psusset
Copy link
Author

psusset commented Feb 14, 2022

HI @jamwitk , I use an HTML button in the page and not a button on the unity side. I think it's not possible to use a button inside of Unity because the deviceorientationrequest must be handled by the webpage.
But you can display your html button on top of the Unity canvas to get the same result. Thanks to javascript call, Unity can control the display of the button.

@jamwitk
Copy link

jamwitk commented Feb 14, 2022

Thank you for your feedback, I have tried write into .jslib and call on start but it gives error such that it need user gesture something like this. It seems as you say it is not possible.

mergeInto(LibraryManager.library, {
   CheckForPermission : function (){
       if (typeof(DeviceOrientationEvent) !== "undefined" && typeof(DeviceOrientationEvent).requestPermission === 'function')
       {
           DeviceOrientationEvent.requestPermission().then(
               function(response) {
                   if (response === 'granted') {
                      window.alert("granted 1");
                   }
               }).catch(function (error) {
               window.alert(error);
           });
       }
       else
       {
           window.alert("granted 2");
       };
   },
})

@De-Panther
Copy link
Owner

I think that in Unity 2022.1 beta they added gyro support for WebGL.
So there should be a way to allow gyro from Unity and not just from the page

@De-Panther
Copy link
Owner

Also, if you have relevant device, you should be active in the WebXR Polyfill issue I mentioned and the other relevant issues mentioned there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants