Search Unity

Non-VR App with "Toggle VR" button ?

Discussion in 'VR' started by MBlomme, Jul 10, 2018.

  1. MBlomme

    MBlomme

    Joined:
    Dec 18, 2017
    Posts:
    11
    Hi everyone !

    I am currently developing a software that reproduces an existing WebVR app which basically consists in a 360 scene viewer.
    The WebVR app has a classic browser view in which we can click and drag to rotate the camera and a "toggle VR" button which enables the view in a MR device if used in Edge.
    In my app I already implemented the basic view, but I can't find a way to create the same kind of "toggle VR" button for MR headsets, is there a way to do so in Unity ? I already have this feature implemented for Android using Google Cardboard so I assume the same kind of thing is possible ?

    Thanks in advance
     
  2. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    404
    It sounds like what you want could be this, https://docs.unity3d.com/ScriptReference/XR.XRSettings.html

    You can enable/disable the XR setting via script using the info in that documentation. To start as a flat 2D app on your computer, enable the XR setting in the inspector panel and then add "None" to the XR SDK list as the top most slot so no XR device gets activated initially. From there you can add device SDK's under it and load those dynamically based on events or buttons, or whatever you want in your scripts. Let me know if that does what you were thinking.
     
  3. yy1996

    yy1996

    Joined:
    Jul 12, 2018
    Posts:
    2
    I have tried it but it is not use.
     
  4. MBlomme

    MBlomme

    Joined:
    Dec 18, 2017
    Posts:
    11
    Thank you very much JasonCostanza it works perfactly well !
    You just forgot to precise we have to use XRSettings.LoadDeviceByName("WindowsMR"); before enabling XRSettings, maybe that's why you didn't succeed yy1996 (or maybe you didn't include the SDK ? Or maybe you work on standalone instead of Windows Universal Platform ?)

    My final SwitchToVR Coroutine looks like this:

    Code (CSharp):
    1. IEnumerator SwitchToVR()
    2.     {
    3.         XRSettings.LoadDeviceByName("WindowsMR");
    4.  
    5.         // Wait one frame!
    6.         yield return null;
    7.  
    8.         // Now it's ok to enable VR mode.
    9.         XRSettings.enabled = true;
    10.     }
    (note that it also works with OpenVR when working on standalone)
     
    FlightOfOne and JasonCostanza like this.
  5. yy1996

    yy1996

    Joined:
    Jul 12, 2018
    Posts:
    2
    [QUOTE =“MBlomme,帖子:3561194,成员:1615082”]非常感谢JasonCostanza,它的表现非常好!
    你只是忘了我们必须使用XRSettings.LoadDeviceByName(“WindowsMR”); 在启用XRSettings之前,也许这就是为什么你没有成功yy1996(或者你可能没有包含SDK?或者你可能在独立而不是Windows Universal Platform上工作?)

    我的最终SwitchToVR Coroutine看起来像这样:

    [code = CSharp] IEnumerator SwitchToVR()
    {
    XRSettings.LoadDeviceByName( “WindowsMR”);

    //等一帧!
    yield return null;

    //现在可以启用VR模式了。
    XRSettings.enabled = true;
    }[/码]

    (请注意,在独立工作时,它也适用于OpenVR)[/ QUOTE]
    Thank you very much.I have solved the problem.I made a spelling mistake.it is my first time to do it. Thanks again.
     
    JasonCostanza likes this.
  6. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    404
    Thank you for catching that miss MBlomme, you are correct.